SO_REUSEADDR in NodeJs using net package - javascript

I have two backends. Backend A and Backend B.
Backend B sends and receives info using a socket server running at port 4243.
Then, with Backend A, I need to catch that info and save it. But I have to also have a socket server on Backend A running at port 4243.
The problem is that, when I run Backend A after running Backend B I receive the error "EADDRINUSE", because I'm using the same host:port on both apps.
If, for Backend A I use Python, the problem dissapear because I have a configuration for sockets that's called SO_REUSEADDR.
Here we have some examples:
https://www.programcreek.com/python/example/410/socket.SO_REUSEADDR
https://subscription.packtpub.com/book/networking-and-servers/9781849513463/1/ch01lvl1sec18/reusing-socket-addresses
But, I want to use JavaScript for coding my Backend A, so I was using the net package for coding the sockets, and I can't get it to work, because of the "EADDRINUSE" error.
The NodeJS documentation says that "All sockets in Node set SO_REUSEADDR already", but it doesn't seem to work for me...
This is my code so far:
// Step 0: Create the netServer and the netClient
console.log(`[DEBUG] Server will listen to: ${HOST}:${PORT}`);
console.log(`[DEBUG] Server will register with: ${AGENT_ID}`);
const netServer = net.createServer((c) => {
console.log('[netServer] Client connected');
c.on('message', (msg) => {
console.log('[netServer] Received `message`, MSG:', msg.toString());
});
c.on('*', (event, msg) => {
console.log('[netServer] Received `*`, EVENT:', event);
console.log('[netServer] Received `*`, MSG:', msg);
});
}).listen({
host: HOST, // 'localhost',
port: PORT, // 4243,
family: 4, // ipv4, same as socket.AF_INET for python
});
// Code copied from nodejs documentation page (doesn't make any difference)
netServer.on('error', function (e) {
if (e.code == 'EADDRINUSE') {
console.log('Address in use, retrying...');
setTimeout(function () {
netServer.close();
netServer.listen(PORT, HOST);
}, 1000);
}
});
const netClient = net.createConnection(PORT, HOST, () => {
console.log('[netClient] Connected');
});
// Step 1: Register to instance B of DTN with agent ID 'bundlesink'
netClient.write(serializeMessage({
messageType: AAPMessageTypes.REGISTER,
eid: AGENT_ID,
}));
With this code, I get the following output in the terminal:
But, with the Python code, the socket connects successfully:
I don't know what to do :(
I hope I get some help here.
Edit 1
By the way, the lsof command, throws me this output for the JavaScript backend:
And this other output for the Python backend:
Edit 2
It really seems to be a problem with JavaScript. I also found this snippet:
var net = require('net');
function startServer(port, host, callback) {
var server = net.createServer();
server.listen(port, host, function() {
callback(undefined, server);
});
server.on('error', function(error) {
console.error('Ah damn!', error);
callback(error);
});
}
startServer(4000, '0.0.0.0', function(error, wildcardServer) {
if (error) return;
startServer(4000, '127.0.0.1', function(error, localhostServer) {
if (error) return;
console.log('Started both servers!');
});
});
From this post:
https://medium.com/#eplawless/node-js-is-a-liar-sometimes-8a28196d56b6
As the author says:
Well, that prints “Started both servers!” which is exactly what we don’t want.
But for me, instead of printing that, I get an error:
Ah damn! Error: listen EADDRINUSE: address already in use 127.0.0.1:4000
at Server.setupListenHandle [as _listen2] (node:net:1319:16)
at listenInCluster (node:net:1367:12)
at doListen (node:net:1505:7)
at processTicksAndRejections (node:internal/process/task_queues:84:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '127.0.0.1',
port: 4000
}
I really cannot make it to run and print "Started both servers!".
Because that's what I want my code to do.
Edit 3
This is the Python server socket: https://gitlab.com/d3tn/ud3tn/-/blob/master/tools/aap/aap_receive.py
This is the important part:
addr = (args.tcp[0], int(args.tcp[1])) # args.tcp[0] = "localhost", args.tcp[1] = "4243"
with AAPTCPClient(address=addr) as aap_client:
aap_client.register(args.agentid) # args.agentid = "bundlesink"
run_aap_recv(aap_client, args.count, args.verify_pl)
It creates an AAPTCPClient, and the only thing that AAPTCPClient does, is the following:
def __init__(self, socket, address):
self.socket = socket
self.address = address
self.node_eid = None
self.agent_id = None
def register(self, agent_id=None):
"""Attempt to register the specified agent identifier.
Args:
agent_id: The agent identifier to be registered. If None,
uuid.uuid4() is called to generate one.
"""
self.agent_id = agent_id or str(uuid.uuid4())
logger.info(f"Sending REGISTER message for '{agent_id}'...")
msg_ack = self.send(
AAPMessage(AAPMessageType.REGISTER, self.agent_id)
)
assert msg_ack.msg_type == AAPMessageType.ACK
logger.info("ACK message received!")
def send(self, aap_msg):
"""Serialize and send the provided `AAPMessage` to the AAP endpoint.
Args:
aap_msg: The `AAPMessage` to be sent.
"""
self.socket.send(aap_msg.serialize())
return self.receive()
def receive(self):
"""Receive and return the next `AAPMessage`."""
buf = bytearray()
msg = None
while msg is None:
data = self.socket.recv(1)
if not data:
logger.info("Disconnected")
return None
buf += data
try:
msg = AAPMessage.parse(buf)
except InsufficientAAPDataError:
continue
return msg
I don't see any bind, and I don't understand why the python code can call "socket.recv", but in my JavaScript code I can't do "netServer.listen". I think it should be the same.

There are things to clarify.
1.) The client uses the bind syscall where the kernel selects the source port automatically.
It does so by checking sys local_portrange sysctl settings.
1.) If you want to bind the client to a static source port, be sure to select a TCP port outside the local_portrange range !
2.) You cannot subscribe to event "*", instead you've to subscribe to the event "data" to receive messages.
For best practice you should also subscribe to the "error" event in case of errors !
These links will get you started right away:
How do SO_REUSEADDR and SO_REUSEPORT differ?
https://idea.popcount.org/2014-04-03-bind-before-connect/
So, for all beginners, who want to dig deeper into networking using node.js…
A working server example:
// Step 0: Create the netServer and the netClient
//
var HOST = 'localhost';
var PORT = 4243;
var AGENT_ID = 'SO_REUSEADDR DEMO';
var net = require('net');
console.log(`[DEBUG] Server will listen to: ${HOST}:${PORT}`);
console.log(`[DEBUG] Server will register with: ${AGENT_ID}`);
const netServer = net.createServer((c) => {
console.log('[netServer] Client connected');
c.on('data', (msg) => {
console.log('[netServer] Received `message`, MSG:', msg.toString());
});
c.on('end', () => {
console.log('client disconnected');
});
c.on('error', function (e) {
console.log('Error: ' + e.code);
});
c.write('hello\r\n');
c.pipe(c);
}).listen({
host: HOST,
port: PORT,
family: 4, // ipv4, same as socket.AF_INET for python
});
// Code copied from nodejs documentation page (doesn't make any difference)
netServer.on('error', function (e) {
console.log('Error: ' + e.code);
if (e.code == 'EADDRINUSE') {
console.log('Address in use, retrying...');
setTimeout(function () {
netServer.close();
netServer.listen(HOST, PORT);
}, 1000);
}
if ( e.code = 'ECONNRESET' ){
console.log('Connection reset by peer...');
setTimeout(function () {
netServer.close();
netServer.listen(HOST, PORT);
}, 1000);
}
});
The Client:
/* Or use this example tcp client written in node.js. (Originated with
example code from
http://www.hacksparrow.com/tcp-socket-programming-in-node-js.html.) */
var net = require('net');
var HOST = 'localhost';
var PORT = 4243;
var client = new net.Socket();
client.setTimeout(3000);
client.connect(PORT, HOST, function() {
console.log("Connected to " + client.address().address + " Source Port: " + client.address().port + " Family: " + client.address().family);
client.write('Hello, server! Love, Client.');
});
client.on('data', function(data) {
console.log('Received: ' + data);
client.end();
});
client.on('error', function(e) {
console.log('Error: ' + e.code);
});
client.on('timeout', () => {
console.log('socket timeout');
client.end();
});
client.on('close', function() {
console.log('Connection closed');
});
Best Hannes

Steffen Ullrich was completely right.
In my JavaScript code, I was trying to create a server to listen to the port 4243.
But you don't need to have a server in order to listen to some port, you can listen with a client too! (At least that's what I understood)
You can create a client connection as following:
const netClient = net.createConnection(PORT, HOST, () => {
console.log('[netClient] Connected');
});
netClient.on('data', (data) => {
console.log('[netClient] Received data:', data.toString('utf8'));
});
And with "client.on", then you can receive messages as well, as if it were a server.
I hope this is useful to someone else.

Related

Sails js client native websocket

I'm trying to use websockets with sails-js but I can't make it work with native javascript websockets.
the tutorial example use the sails.io.js library and it goes a little bit like this:
io.socket.on('hello', function (data) {
console.log('Socket `' + data.id + '` joined the party!');
});
function sendHello () {
// And use `io.socket.get()` to send a request to the server:
io.socket.get('/websockets/hello', function gotResponse(data, jwRes) {
console.log('Server responded with status code ' + jwRes.statusCode + ' and data: ', data);
});
}
This does work, but i want to use the native javascript websockets like this:
let ws = new WebSocket("ws://localhost:1337/websockets/hello");
ws.onopen = function (e) {
console.log("[open] Connection established");
console.log("Sending to server");
ws.send("My name is John");
};
ws.onmessage = function (event) {
console.log(`[message] Data received from server: ${event.data}`);
};
ws.onclose = function (event) {
if (event.wasClean) {
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
} else {
// e.g. server process killed or network down
// event.code is usually 1006 in this case
console.log('[close] Connection died');
}
};
ws.onerror = function (error) {
console.log(`[error] ${error}`);
console.log(error);
};
Clean and native javascript websockets with no library needed. Unfortunately I can't seem to make it work.
When I try to connect to sails js server using native websockets I get this message:
WebSocket connection to 'ws://localhost:1337/websockets/hello' failed: Connection closed before receiving a handshake response
Impossible to make it connect, it seems like sails js don't even get the message because i make a log when i get a new connection (using the tutorial code):
module.exports = {
hello: function (req, res) {
console.log("web socket received",req.isSocket)
// Make sure this is a socket request (not traditional HTTP)
if (!req.isSocket) {
return res.badRequest();
}
// Have the socket which made the request join the "funSockets" room.
sails.sockets.join(req, 'funSockets');
// Broadcast a notification to all the sockets who have joined
// the "funSockets" room, excluding our newly added socket:
sails.sockets.broadcast('funSockets', 'hello', { howdy: 'hi there!' }, req);
// ^^^
// At this point, we've blasted out a socket message to all sockets who have
// joined the "funSockets" room. But that doesn't necessarily mean they
// are _listening_. In other words, to actually handle the socket message,
// connected sockets need to be listening for this particular event (in this
// case, we broadcasted our message with an event name of "hello"). The
// client-side code you'd need to write looks like this:
//
// io.socket.on('hello', function (broadcastedData){
// console.log(data.howdy);
// // => 'hi there!'
// }
//
// Now that we've broadcasted our socket message, we still have to continue on
// with any other logic we need to take care of in our action, and then send a
// response. In this case, we're just about wrapped up, so we'll continue on
// Respond to the request with a 200 OK.
// The data returned here is what we received back on the client as `data` in:
// `io.socket.get('/say/hello', function gotResponse(data, jwRes) { /* ... */ });`
return res.json({
anyData: 'we want to send back'
});
}
};
How can I make sails js work with native javascript websockets?
Found a simple solution!
Used the npm package ws: npm i ws
making a new hook: sails generate hook customWebSocket
in the hook :
/**
* WS hook
*
* #description :: A hook definition. Extends Sails by adding shadow routes, implicit actions, and/or initialization logic.
* #docs :: https://sailsjs.com/docs/concepts/extending-sails/hooks
*/
const WebSocket = require('ws');
module.exports = function defineWsHook(sails) {
return {
/**
* Runs when this Sails app loads/lifts.
*/
initialize: async function () {
sails.log.info('Initializing custom hook (`WS`)');
console.log("custom hook")
const wss = new WebSocket.Server({ port: 3100 });
wss.on('connection', (socket) => {
console.log('New user connected wss');
socket.on('message', function incoming(message) {
console.log(message)
});
});
}
};
};
Done and done, now i can connect to is using native websocket!
now that i have done that i realize that the socket.io library might be better for handling errors.

How to maintained network connection in Node.js for unlimited requests

I want to make connection for unlimited times in Nodejs. For example, i write something on some server and after writing on server, server send me response of error (as expected from server) and disconnect. But i want to again make a connection to that server and again want to send request with different parameters. I am not sure where and what logic/code to be put in my following segment of code , so that i can make unlimited requests.
var net = require('net');
var HOST = '40.14.121.178'
var PORT = 12537;
var byteToSend = [0x56, 0x34, ...]
var client = new net.Socket();
client.connect(PORT, HOST, function() {
console.log('CONNECTED TO: ' + HOST + ':' + PORT);
client.write(byteToSend);
});
client.on('data', function(data) {
console.log('DATA: ' + data);
client.destroy();
});
client.on('close', function() {
console.log('Connection closed');
});
EDITED:
actually, i want to make another connection upon disconnect like following style (which is i think wrong)
client.on('close', function() {
console.log('Connection closed');
client.connect(PORT, HOST, function() {
console.log('again CONNECTED TO: ' + HOST + ':' + PORT);
client.write(byteToSend);
});
});
above re connection raise following error.
events.js:174
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:78:25)
at writeGeneric (internal/stream_base_commons.js:73:3)
at Socket._writeGeneric (net.js:713:5)
at Socket._write (net.js:725:8)
at doWrite (_stream_writable.js:415:12)
at writeOrBuffer (_stream_writable.js:399:5)
at Socket.Writable.write (_stream_writable.js:299:11)
at bitflipping (C:\Users\...\Desktop\myScripts.js:130:8)
at Socket.<anonymous> (C:\Users\...\Desktop\myScripts.js:104:9)
at Object.onceWrapper (events.js:286:20)
Emitted 'error' event at:
at errorOrDestroy (internal/streams/destroy.js:107:12)
at onwriteError (_stream_writable.js:430:5)
at onwrite (_stream_writable.js:461:5)
at _destroy (internal/streams/destroy.js:49:7)
at Socket._destroy (net.js:613:3)
at Socket.destroy (internal/streams/destroy.js:37:8)
at afterWriteDispatched (internal/stream_base_commons.js:78:17)
at writeGeneric (internal/stream_base_commons.js:73:3)
at Socket._writeGeneric (net.js:713:5)
at Socket._write (net.js:725:8)
I don't think you can re-use the existing client connection to connect again. Therefore, you'll want to wrap it all in a nice closure/function that you can call again to create a new socket and connect.
Try something like this:
var net = require('net');
var HOST = '40.14.121.178'
var PORT = 12537;
var byteToSend = [0x56, 0x34, ...]
function connect() {
var client = new net.Socket();
client.connect(PORT, HOST, function() {
console.log('CONNECTED TO: ' + HOST + ':' + PORT);
client.write(byteToSend);
});
client.on('data', function(data) {
console.log('DATA: ' + data);
client.destroy();
});
client.on('close', function() {
console.log('Connection closed');
connect();
});
}
connect();
If I understood correctly, you want to keep your server enabled for requests for a sort amount of time without waiting for 3-way handshake etc. To do that you should use the keep-alive attribute like this.
const net = require('net');
const HOST = '40.14.121.178'
const PORT = 12537;
const byteToSend = [0x56, 0x34, ...];
const server = net.createServer(client => {
client.setKeepAlive(true, 60000); // milliseconds.
client.on('data', data => {
console.log(`DATA: ${data}`);
client.destroy();
});
client.on('end', data => {
console.log('Connection closed');
});
client.on('connect', data => {
client.write(byteToSend);
});
client.on('error', err => {
console.log(`Error: ${err.message}`);
})
});
server.listen(PORT, HOST, () => {
console.log("server started");
});

How to have a persistent connection with Net in Node.js?

I am using a Telnet - client to validate the emails, I connect to the server and it responds with 250 but when I write another command and ask for the answer, it simply does not answer me.
This is my code:
function ConnectTelnet(){
//var connection = new telnet();
var response;
var HOST = 'mail.dominio.com';
var PORT = 25;
var net = require('net');
var client = net.connect(25,'mail.dominio.com',function(){
console.log('connected to server!');
console.log('CONNECTED TO: ' + HOST + ':' + PORT);
client.on('data', function(data) {
console.log('Received: ' + data);
response = data;
if(response.indexOf("220") === -1){
client.write('EHLO dominio.com')
console.log(data)
}
});
})
}
Does anyone know how I can continue? Thanks :)
You can't send the data, get an answer and then send more data on the same connection. TCP does not send messages "separately". TCP is a stream protocol, which means that when you write bytes to the socket, you get the same bytes in the same order at the receiving end. There is no notion of "message boundaries" or "packets" anything of the sort.
If you want to do that, you need to make a new connection every time.
This is how I did to send several EHLO on the same connection:
const net = require('net');
const client = net.createConnection({ host: '127.0.0.1', port: 1025 }, () => {
console.log('connected to server!');
checkEHLO(client, [ 'xxx#xxx.xxx', 'xxx#xxx.xxx', 'xxx#xxx.xxx' ]);
});
client.on('data', (data) => {
console.log(data.toString());
client.end();
});
client.on('end', () => {
console.log('disconnected from server');
});
function checkEHLO(client, emails){
emails.forEach((email) => {
client.write('EHLO ' + email + '\n');
});
}
And this was the response I got:
connected to server!
220 127.0.0.1 ESMTP Service Ready
250-Hello xxx#xxx.xxx
250-PIPELINING
250-8BITMIME
250-STARTTLS
250 AUTH PLAIN LOGIN
250-Hello xxx#xxx.xxx
250-PIPELINING
250-8BITMIME
250-STARTTLS
250 AUTH PLAIN LOGIN
250-Hello xxx#xxx.xxx
250-PIPELINING
250-8BITMIME
250-STARTTLS
250 AUTH LOGIN PLAIN

Node JS Read display Console output on user's device

Is it possible to display the default console output from a node.js Server to the users client? I've tried several plugins like e.g. 'console.re' but not one of them worked for me.
I like to read the 'console.log' output in real time and display all output to a client (mobile device).
Thanks
console.log writes to stdout, so you can listen to it and do whatever with the data.
console.log([data,][args])
Prints to stdout with newline.
https://nodejs.org/api/console.html
Try advancing this code:
const spawn = require('child_process').spawn
const ls = spawn('ls', ['-lh', '/usr'])
const collectedData = []
ls.stdout.on('data', (data) => {
console.log('stdout: ' + data.toString())
collectedData.push({ event: 'CONSOLE_LOG', data })
// now just make the client consume collectedData in real-time
// or on refresh
})
ls.stderr.on('data', (data) => {
console.log('stderr: ' + data.toString())
})
ls.on('exit', (code) => {
console.log('child process exited with code ' + code.toString())
})
Child processes are built in. Take a sample through these docs here:
https://nodejs.org/api/child_process.html
I don't know anything about your setup, but if you want super easy in Express
app.get('/logging', (req, res) => {
res.send(collectedData)
})
Make the client hit it every 2000ms or something.
Otherwise, you need to create a socket with the server and push updates to the client, and handle them in the client.
http://www.socket.io
You can also setup TCP and UDP sockets fairly quick in node.js. Do some Googling.
I have some sample code I can give you:
/**
* SERVER
*/
// Load dgram module
const dgram = require('dgram')
// Create new socket
const server = dgram.createSocket('udp4')
// Listening event
server.on('listening', () => console.log('UDP Server listening'))
// Message event
server.on('message', (msg, rinfo) => {
console.log(`${rinfo.address}:${rinfo.port} - ${msg}`)
});
// Start UDP socket listener
const PORT = 3333
const HOST = '127.0.0.1'
server.bind(PORT, HOST)
/**
* CLIENT
*/
const client = dgram.createSocket('udp4')
const ip = require('ip')
client.send('Sample message', PORT, HOST, (err) => {
if (err) throw err
console.log(`UDP message sent: ${ip.address()}`)
client.close()
})

Nodejs server unable to detect connection with Pubnub+SocketIO

My nodejs server is unable to detect when a new browser connects ('connection' event) and I dont know why. I narrowed down a problem working on it for a few days and suspect that is has to due with the addition of the pubnub socket connection implemented on the browser.
The following is my server.js
var http = require('http')
, connect = require('connect')
, io = require('socket.io')
, fs = require('fs')
, uuid = require('node-uuid')
, _ = require('lodash');
// pubnub!!! (how to initialize it for use on server)
var pubnub = require('pubnub').init({
channel: "my_channel",
publish_key: "pub-key",
subscribe_key: "sub-c-key",
uuid: "Server",
origin : 'pubsub.pubnub.com'
});
pubnub.subscribe({
channel: 'my_channel',
callback: function(message) {
console.log("Message received: ", message);
},
message: 'Server ready',
presence: function(data) {
console.log("Presense: ", data);
},
connect: publish
});
// various socket.on() events omitted
var app = connect().use(connect.static(__dirname)).use(connect.directory(__dirname));
var server = http.createServer(app);
server.listen(8888);
io = io.listen(server);
io.sockets.on('connection', handleNewPeer);
Upon arriving on the html page, the doConnect(isBroadcaster) function is ran from script tag
The doConnect function (In peer.js):
var doConnect = function(isBroadcaster) {
console.log("doConnect");
// broadcaster or normal peer
var user;
if (isBroadcaster)
user = "Broadcaster";
else
user = "Viewer";
(function() {
var pubnub_setup = {
channel: "my_channel",
publish_key: "pub-c-key",
subscribe_key: "sub-c-key",
user: user
};
// Note removed the var
socket = io.connect( 'http://pubsub.pubnub.com', pubnub_setup);
// various socket.on() omitted
})();
Here is what how it was before with just socketIO & it was working:
var doConnect = function(isBroadcaster) {
socket = io.connect();
// various socket.on() omitted
}
My p2p video website is implemented with WebRTC running on a Nodejs + SocketIO server.
I have been trying to incorporate pubnub into it & thought it would be easy since pubnub supports SocketIO (or at least client side?). Really did not think it would be this difficult to set up server side.
Any input at all on this? I think it's something simple that I just cannot put my finger on
Socket.IO on the Server using Node.JS
Socket.IO with PubNub does not provide a Node.JS Socket.IO backend option. However you can use the PubNub SDK directly for on-connect events.
NPM Package
npm install pubnub
After you install the PubNub NPM you can use the node.js server backend:
Node.js Backend Code
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// PubNub!!! (how to initialize it for use on server)
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
var pubnub = require('pubnub').init({
publish_key : "pub-key",
subscribe_key : "sub-c-key",
uuid : "Server-ID"
});
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// On user Connect
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function on_user_connect(data) {
console.log( "User Connected: ", data.uuid );
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// On user Leave
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function on_user_leave(data) {
console.log( "User Left: ", data.uuid );
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Open Socket Connection for User Join Events
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pubnub.subscribe({
channel : 'my_channel',
connect : connected
message : function(message) {
console.log("Message received: ", message);
},
presence : function(data) {
if (data.action == "leave") on_user_leave(data);
if (data.action == "timeout") on_user_leave(data);
if (data.action == "join") on_user_connect(data);
}
});
function connected() {
console.log('connected!');
}
What version of socket.io are you using?
This might not fix it. I am using version 1.+ Have you tried:
io.on('connection', function(socket){
console.log('user connected');
});

Categories