Question

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?

Was it helpful?

Solution 2

TCP and WebSocket are not the same protocol or framing, so wiring them up blindly isn't going to work. Well ... technically, websocket is an upgrade of http which is layered on ssl (optionally) which in turn is layered on tcp.

TCP can be thought of as a stream of bytes, while WebSocket is a set frames.

WebSocket frames can be any of the following:

  • TEXT - consists of 1 or more frames making up a single UTF8 message
  • BINARY - consists of 1 or more frames making up a byte array message
  • CONTINUATION - used by TEXT and BINARY to piece together 2 or more frames.
  • PING - obvious
  • PONG - obvious
  • CLOSE - request a close/disconnect of the protocol.

In short, you'd need to implement the websocket protocol framing in order to have TCP wired up to websocket. And you'll need to implement basic HTTP UPGRADE in order to reach that point.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top