Any way to get the ws client to talk with a socket.io server?
When I try, I currently get a socket hang up on the client.
On the socket.io server side, the log says "destroying non-socket.io upgrade"
I realize the issue is likely on the socket.io end of things, but I thought maybe someone had gotten it working and was willing to share.
You should be using the Socket.IO client to connect to socket.io not pure websockets. Socket.IO adds to much things on top of websockets to make this plausable like a required HTTP handshake to retrieve the session id as well as custom message encoding and decoding
With current version of ws and socket.io this snippet worked for me
const WebSocket = require('ws');
const ws = new WebSocket('ws://server/socket.io/?EIO=3&transport=websocket', {
perMessageDeflate: false
});
ws.on('open', function open() {
console.log("opened");
});
@sand123 workaround did not work around for me.
const chat = new WebSocket(
'ws://'+chatserver+'/chat/?EIO=3&transport=websocket',
{perMessageDeflate: false}
)
chat.on('error', function(e){
console.log("chat error:"+e.message)
})
chat.on('open', function() {
console.log('chat open');
//chat.send('name');
});
I always get chat error:socket hang up. On the other hand, this is running on a robot with an old version of Ubuntu 12 so maybe that's the issue. I was really hoping this could work because it needs to be lightning fast. Oh well. I wish there had been an open issues or a note that said "This isn't known to work to connect to a server running Socket.IO" so I hadn't wasted my time.
In your case, shouldn't it be
const chat = new WebSocket(
'ws://'+chatserver+'/chat/socket.io/?EIO=3&transport=websocket',
{perMessageDeflate: false}
)
?
With current version of
wsandsocket.iothis snippet worked for meconst WebSocket = require('ws'); const ws = new WebSocket('ws://server/socket.io/?EIO=3&transport=websocket', { perMessageDeflate: false }); ws.on('open', function open() { console.log("opened"); });
Can you show me example on this issue?
Most helpful comment
With current version of
wsandsocket.iothis snippet worked for me