1

I am using a library (ShareDB) for operational transformation, and the server and client side use a websocket-json-stream to communicate. However this ShareDB is being run on nodejs as a service (I'm using zerorpc to control my node processes), as my main web framework is Tornado (python). I understand from this thread that with a stateful protocol such as TCP, the connections are differentiated by the client port (so only one server port is required). And according to this response regarding how websockets handle multiple incoming requests, there is no difference in the underlying transport channel between tcp and websockets.

So my question is, if I create a websocket from the client to the python server, and then also from the client to my nodejs code (the ShareDB service) how can the server differentiate which socket goes with which? Is it the servers responsibility to only have a single socket 'listening' for a connection a given time (i.e. to first establish communication with the Python server and then to start listening for the second websocket?)

Community
  • 1
  • 1
Flaminator
  • 564
  • 6
  • 17
  • I can't quite follow what is connecting to what. You use the term "server" and "client" without enough description for what you mean. It sounds like you have two servers (a python server and a nodejs server) and a client. So, I would assume the client is connecting to each of your two separate servers. But, then you ask how the server can differentiate, but each server should only have one connection to a given client? Confused about what you're trying to do. FYI, you would typically identify incoming webSocket connections the same way you identify incoming http connections with cookies. – jfriend00 Jan 02 '17 at 22:46
  • If you're connecting from the client to each of your separate servers on the same physical server computer, then each of your server processes would be listening on a different port and the client would connect to the appropriate port to identify which server it is connecting to. – jfriend00 Jan 02 '17 at 22:53
  • Thanks, I think you've summarized it better than i had formulated it so I will edit the wording. Both servers are on the same physical system... I'm using Heroku and as I understand it they only allow a single port to be open. – Flaminator Jan 02 '17 at 22:58
  • You will either need a separate incoming port open (one for each server) or you will need to use a proxy that can split the incoming connections on one port to to separate ports for your two server processes. The proxy can be configured a number of ways. It can use the webSocket URL or a DNS hostname to know which server process a given connection is targeted for. – jfriend00 Jan 02 '17 at 23:01

1 Answers1

2

The simplest way to run two server processes on the same physical server box is to have each of them listen on a different port and then the client connects to the appropriate port on that server to indicate which server it is trying to connect to.

If you can only have one incoming port due to your server environment, then you can use something like a proxy. You still have your two servers listening on different ports, but neither one is listening on the port that is open to the outside world. The proxy listens on the one incoming port that is open to the outside world and then based on some characteristics of the incoming connection, the proxy directs that incoming connection to the appropriate server process.

The proxy can be configured to identify which process you are trying to connect to either via the URL or the DNS hostname.

jfriend00
  • 683,504
  • 96
  • 985
  • 979