Tuesday 26 September 2017

Getting disconnected ws (websocket) port

I'm not usually a node.js developer but I've inheritted a code base encountering an issue. After two days of debugging I was hoping a kind soul could spare a few moments. I have a server that keeps a list of IP+ports to determine connected clients. When a disconnect happens it is now unable to gather which port that message is coming from. I believe if I can get the port that was disconnected that will fix my issue.IP&Port are gotten on connection (wss.on('connection',...) via ws._socket.remoteAddress + ':' + ws._socket.remotePort;IP&Port are gotten during disconnect (ws.on('close',)...) via ws._socket._peername.address + ':' + ws._socket._peername.port;When the ws.on('close' even occurs however ws._socket is null. This code used to function, through update or who knows what it no longer does. I've been digging through quickstarts and API docs looking for instances of usage with ws._socket._peername.port and mostly what I find is very little, a few people suggesting it and no complaints.If I remove this functionality, and don't try to delete clients from the client list, I get 'Error: not opened at WebSocket.send' errors which the Internet tells me is likely due to poor client cleanupIf I try to use just the IP instead of an IP+port combo I get the above error as well.pastebin of clientHandler.jspastebin of server.jsAny help is muchappreciated as I'm sort of at the end of my debugging capabilities for Node.js since I haven't really had much to do with it up till this point. The purpose of the server is to serve numbers to web pages which are served up via apache.

Submitted September 26, 2017 at 11:42PM by anonmarmot

No comments:

Post a Comment