Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to Socket.io server with standard web-socket client

Is it possible connect to socket.io server with standard web-socket client? When connecting to socket.io server through socket.io client, Url started with HTTP but for web-socket clients must use ws. so, if it is possible, how to connect to socket.io server and what is the url for connecting to socket.io server?

like image 430
Behrooz Avatar asked Dec 11 '14 07:12

Behrooz


People also ask

Can WebSocket connect to Socket.IO server?

Although Socket.IO indeed uses WebSocket as a transport when possible, it adds additional metadata to each packet. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a plain WebSocket server either.

How do I connect Socket.IO to frontend?

You need to pass your server there, not the http module and you need to assign the result to an io variable. So, after you've defined and initialized your server variable, you would do: const io = require("socket.io")(server);


1 Answers

socket.io has a protocol on top of webSockets. If you're going to use socket.io on the server side, then you have to use a socket.io-compatible client on the other end.

So, you can't use a plain webSocket client to connect to a socket.io server.

The socket.io protocol is here.

like image 105
jfriend00 Avatar answered Sep 27 '22 23:09

jfriend00