7 ms·
The server generally only ever uses one port, no matter how many clients are connected. It is the tuple of (client IP, client port, server IP, server port) tha
by caf 15y ago
The server generally only ever uses one port, no matter how many clients are connected. It is the tuple of (client IP, client port, server IP, server port) that must be unique for each TCP connection - so the limit of 65535 ports is only relevant for how many connections a single client can make to a single server.
- richardw 15y agoYou can have multiple connections on the same port from the same client. E.g. all connections via HTTP commonly go over the same port and a single browser usually has 2-4 simultaneous connections to the server. They don't use multiple ports to achieve this.
- caf 15y agoThey use multiple ports on the client side to achieve this - the "client port" part of the tuple varies.
- nathanappere 15y agoI believe this is incorrect. The server usually listen on one port, but everytime it does an accept, a different random port is used, and the client start talking to the server on that new port.
- caf 15y agoThis is a surprisingly common misconception. When you accept, you get a new socket. but it is on the same local port. You can readily see this by running 'netstat' on a busy server.
- ay 15y agoAnother way to see that there are no magic "dynamically selected" potrs is to run on the server "tcpdump src x.x.x.x or dst x.x.x.x" where the x.x.x.x is your client address - and check the outputs - the packets will have ports in them. Alternatively one can read RFC793 or, better, Stevens' "TCP/IP Illustrated".
- nathanappere 15y agoJust checked it and you're right. I believed I had encoutered the behaviour I described but I do not remember in which context. Anyway glad I learned something!
- dsl 15y agoFTP.
- pavelkaroukin 15y agoI believe this comes from how FTP protocol works which do it to some extent and the reason why it do not work trough firewalls well without using passive mode.
- tybris 15y agoBy that logic, you would have to open every single port on your firewall if you wanted to set up a web server. Fortunately, your OS just looks at the client IP/port to distinguish multiple TCP streams.