TCP socket for websocket?

There are many websocket β†’ socket sockets wrappers (like websockify ), but is there some kind of opposite? In particular, I want to be able to connect to the TCP socket with the application, and the proxy to be transferred to websocket and to another web server server.

+4
source share
3 answers

Bridging a connection with a WebSocket client on a TCP server is a common solution that encapsulates the lower layer TCP protocol into the higher layer WebSocket protocol. This allows the browser (or other web server clients) to communicate with arbitrary TCP servers. Note that the client application (JavaScript) should still be able to decode / encode the protocol that the TCP server is talking about.

The reverse action is not common and will require special framing of messages from the TCP client application to the bridge, so that the bridge knows how to encode WebSocket messages to the TCP server. WebSockets is a message-based transport, and TCP is a lower-level transport stream. The TCP transport layer does not have the concept of messages in the protocol itself, so it needs to be processed at a high level. In other words, you will need to do almost as much work so that your TCP client application can interact with the bridge application, as would be necessary to implement the WebSocket client directly in your application. In fact, this is probably less to implement directly, because WebSocket client libraries are already available for most popular languages.

You will not be able to connect a pre-existing TCP client through the bridge to the existing WebSocket server without changing the client or the bridge (to add the message border and information about the operation codes), or you will need a special WebSocket server that ignores the WebSiocket message boundaries and processes incoming data in the form of a stream (with message processing it is processed at a higher level).

Perhaps you could use a use case where, in your opinion, this might be useful?

Disclaimer I did websockify.

+5
source

I'm not sure what you were looking for, but in case this helps someone in the future, I will write what I did to solve my problem.

My problem: I wanted to be able to host noVNC on my web application server, and I wanted servers without websocket vnc to figure this out without using websockify.

My solution: I used the ws-tcp-bridge node.js module to connect the websocket <- lport> port, where the noVNC client will connect to the vnc host of the tcp server.

Example: This happens when you run the following command from the vncserver machine:

ws-tcp-bridge --method=ws2tcp --lport=5555 --rhost=127.0.0.1:5902

Thus, I was able to host vncserver without websocket on port 5902 and connect to it through noVNC on port 5555 .

I haven’t tested this very much, but it works great with x11vnc vnc server.

+1
source

I do not quite understand what you are asking, but the WebSocket API is mainly used on the client side.

How you code the server side of the script, and what language you use for this, is entirely up to you. When encoding your server side script, you should be able to choose whether to use a TCP socket or not, etc.

0
source

All Articles