I'm trying to connect my node tcp server to my socket.io server using websockify in javascript. I found the git repo for it at https://github.com/novnc/websockify/wiki/websock.js , but can't seem to find how to start it off in code. Can anyone provide an example or point me to some kind of documentation for the js version? Also, when I download websockify off of npm, I don't receive websock.js, if anyone can tell how to do that too I'd appreciate it.
Connecting Nodejs tcp server to a websockit
298 views Asked by Eduardo At
3
There are 3 answers
0
On
Websocket needs an HTTP(s) server. You cannot connect it to a TCP server.
You can try express.js.
A socket.io server can only talk to a socket.io client. So, you cannot connect a plain TCP server to a socket.io server. To connect to a socket.io server, you need a socket.io client. You can certainly get the socket.io-client for node.js and then you can use that to connect to a socket.io server.
Let me explain a bit. socket.io is built on top of webSocket and has it's own connection initiation on top of webSocket. webSocket uses HTTP to initiate a connection and then after some connection handshaking switches to the webSocket protocol. If any of those pieces are missing, the connection will fail to get established and/or will shut-down shortly after connecting.
So, to connect to a socket.io server, all of the following has to happen:
So, only a socket.io client, using a supported transport (typically webSocket) can connect to a socket.io server. You can't use a webSocket client to connect to a socket.io server. You can't use a plain TCP client. You can't use an HTTP client.