I would like to test my engine.io server with multiple connections. I am trying to open sockets in loop, but output is only one socket.
In socket.io-client I added forceNew: true
and fixed the issue but not working with engine.io-client.
for (var i=0;i<10;i++){
var socket = require('engine.io-client')('ws://localhost');
socket.on('open', function(){
console.log('socket opened : '+socket.id);
socket.on('message', function(data){
console.log('data is '+data);
});
socket.on('close', function(){
console.log('socket closed : '+socket.id);
});
});
}
With the socket.io-client, you have to set multiplex: false
.
It creates a new Manager for the given URL, and attempts to reuse an existing Manager for subsequent calls, unless the multiplex option is passed with false. Passing this option is the equivalent of passing 'force new connection': true.
More at: http://socket.io/docs/client-api/
However, there seems to be no such implementation for "engine.io-client" and I don't think there will be either.
The recommended framework for building realtime applications is Socket.IO, since it provides fundamental features for real-world applications such as multiplexing, reconnection support, etc.