Here is my code snippet:
function MyClass(udpSocket)
{
this.IPSocket = udpSocket;
this.port;
this.DestAddr;
}
MyClass.prototype.handleMessage = function(message)
{
var msg = JSON.parse(message);
switch(msg.type)
{
case "Send":
var BufToSend = "Hey";
this.IPSocket.send(BufToSend, 0, BufToSend.length, this.port, this.DestAddr, function(err, bytes)
{
if (err) throw err;
});
break;
MyClass.prototype.setWebSocketConnection = function( ws)
{
this.wsConnection = ws;
this.wsConnection.on('message', function incoming(message)
{
MyClass.prototype.handleMessage( message );
});
}
MyClass.prototype.setUdpPort = function( PORT )
{
this.port = PORT;
}
MyClass.prototype.setDestAddr = function( DEST_ADDR )
{
this.DestAddr = DEST_ADDR;
}
exports.mMyClass = MyClass;
The issue arises when I try to access the member variables of MyClass within the handleMessage callback and cannot send a message over udpSocket. Any suggestions on how to solve this problem?