Is there a way to switch the connection to another TCP server?

I have made my personal project using WebSocket.

I already know that WebSocket will not connect directly raw TCP Socket.

so, I have thought what if I connect, at first, to Web Server(NodeJS) and then switch to TCP server.

is It possible to switch connection to another server using NodeJS?

If so.

Please let me happy.. Thank you! have a nice day.

I would assume it might be both possible and straightforward to tunnel/proxy TCP traffic. The high level design would be:

  • Start up a web server with integrated websocket server (use socket.io, really)
  • When a client makes a websocket connection, create an upstream TCP connection to your target server
  • Then do full bidirectional piping of messages between the browser<->node socket and the node<->otherServer socket

Devil might be in the details. I haven't tried, but seems feasible.

There's a node project called ws-tcp-bridge as well as a python project that claim to do this already. Neither luke terribly mature, but they might just work or at least provide good reference material.