Jake Cross
Jake Cross

Reputation: 523

Transporting Socket.IO socket to another server

How can I transport a Websocket that connects to Server A (Which is using Socket.IO) to Server B each time data is sent, and be able to send data to that socket from Server B. But on top of all of that, the socket should not be able to send data to Server B directly, all data going into the servers must be going to server A. Would I be able to just pass the socket object from Server A to B? Note: Any request server B gets is being authenticated from Server A.

I hope this isn't too confusing the way a worded it. Here's a text diagram.

Socket -> Server A -> Server B -> Socket

Upvotes: 0

Views: 1084

Answers (1)

jfriend00
jfriend00

Reputation: 707328

You cannot pass a socket from one server to another. A given TCP socket (which socket.io is based on) is between two specific endpoints only and you cannot change that once the socket has been connected.

Your question is not entirely clear, but it sounds like maybe you just want server A to act like a proxy where the client connects to server A and then server A can decide to forward some data on to server B. You can either use a pre-existing proxy server that supports your method of authentication in place of server A or if you already have a server A process, then you can add proxying capabilities to it by just having it send appropriate packets of information to server B.

Or, you can have a socket connect to server A, authentication through server A and as part of that connection, it could receive a token which would it could then use to directly connect to server B. Server A and B would share access to some "token store" so that server B could check the token store to see if any incoming connection has presented a valid token or not.

Upvotes: 1

Related Questions