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.
source share