Is it possible to have a TCP Socket server running which accepts incoming connections from WebSocket clients? I have a TCP Socket server and I'd like to be able to test this in a browser. Is this possible?
WebSocket is a special protocol that uses HTTP for handshake and use the underlaying socket to do the real communication afterwards. So, you cannot connect to a regular tcp socket with websocket because they are two different things.
Web browsers do not support communicating with TCP hosts, other than web servers. In this post I take a different tack. I demonstrate a relay written with Node. js, that receives data from the browser over websockets, and sends it to a TCP socket.
WebSocket uses a unified TCP connection and needs one party to terminate the connection. Until it happens, the connection remains active. HTTP needs to build a distinct connection for separate requests. Once the request is completed, the connection breaks automatically.
The WebSocket protocol is an independent TCP-based protocol.
Absolutely! That is the purpose of websockify.
Of course your WebSocket client application will need to be able to implement the protocol of the TCP server. For example, noVNC is a browser VNC client that implements the RFB protocol and by using websockify it can connect to a normal TCP based VNC server.
Disclaimer: I created both websockify and noVNC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With