Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have some basic questions about ports and sessions. Since all these are related and simple questions, I've asked them together:

  1. I understand that for creating a connection we need a socket (ip+port) on both client & server. So if one connection is established, then those ports won't be used for other connections, right? But HTTP(80) or SSH(22) is allowing multiple clients to access that port. How?

  2. I read that there is a limitation on the number of ports(~65536) available in a machine. So what does the server need to do if we require more than that (for example, Facebook or Gmail who have a lot of clients)?

  3. I can read how handshake happens before creating a TCP session, but I am not sure how it maintains the connections. For example, if I unplug my ethernet cable, how does my server know that the client lost this connection? Is any pooling mechanism performed between client and server with some interval in TCP connection?

share|improve this question

1 Answer 1

up vote 3 down vote accepted
  1. The server does not track "connections" by just using it's own port and ip but the client's too. So while two clients could be connecting to the same destination IP and port on the server, the clients are coming from different source IP/Port combinations and the server keeps them apart by using that.

  2. As I mentioned in the first answer, multiple connections do not need to use multiple ports on the server side to make a "connection" (see answer 1), so the only way you would run out of space is if you where hosting 65536 different programs1 on the server at the same time that all needed internet connections at the same time.

  3. The software that established the connection can set a "timeout" so if the connection was broken (like in your unplugging example) after a pre-set amount of time if the software gets no new packets from the other end the program assumes the other end lost it's connection and closes it's own side of the connection.

For learning more about how TCP works, I really recommend the Security Now! episodes on how the internet works

You may want to also listen to the listener feedback episodes too as they clarify things that people wrote in and said they wanted more of a explanation on.


1: multiple connections from the same program could use the same port as long as the other end of the connection has a different ip/port combination

share|improve this answer
    
Great Thanks!! scott. I still now thought that each client connection requires one port at server side :(. Also i will read that TCP keep alive mechanism (timeout). Thanks again! –  Kanagavelu Sugumar Feb 16 '13 at 5:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.