4 ms·
A simple question. How come two programs can run on the same port? How does this being implemented?
by antoaravinth 12y ago
A simple question. How come two programs can run on the same port? How does this being implemented?
- thedufer 12y agoI haven't read it too carefully but typically something like this would be done by having one program run on the port in question and then it would determine which protocol a given connection is speaking and hand it off to a different port based on config. So your https and ssh servers run on, say, 2000 and 3000 and the protocol recognizer runs on 443 and hands off connections to either 2000 or 3000. See, for example, reverse-proxying with nginx or haproxy.
- antoaravinth 12y agoYa I guess this is the way that they would have implemented.
- dfox 12y agoFor the case of ssh versus ssl the detection is trivial: first message for ssl comes from client but for ssh first message comes from server. So server simply waits for a while and assumes that client speaks ssh when it does not receive anything. One can also match whatever is received in first message from client against known protocols (this approach makes it possible to for example run HTTP and HTTPS on same port as is done by IPP servers, particularly CUPS).
- antoaravinth 12y agoWhat do you mean by: first message for ssl comes from client but for ssh first message comes from server
- userbinator 12y agoWith SSL/TLS, the client connects and sends a ClientHello message first, and then the server responds; with SSH, the server will send a version string upon connection (and expects the client to do the same). With plain HTTP, the client sends the request first. The server can detect which one of these cases it is.
- antoaravinth 12y agoI'm still being not clear of what you mean by: >with SSH, the server will send a version string upon connection (and expects the client to do the same). Say for example if I do: ssh some.machine.com I'm (being the client ) call the ssh port ( server ) running on the some.machine.com, right? If thats the case, client is who starting the conversation right? Correct me if I'm wrong.
- nickcano 12y agoEstablishing a connection isn't considered 'sending a message'.
- antoaravinth 12y agoOh ok. Now I understood, thanks.