1

Admittedly this is a simple question but 20 minutes of googling and I just can't find an answer... I will frame my question with an example.

say I own www.reallypopular.com and my website sees 100 GET requests per second. Also let's say the average time for my server to respond to that GET request is 1 second (for the sake of the example just assume some server side processing.) My understanding of ports would say that the first client to contact my server would then block anyone else from connection to port 80 for 1 second. Following this logic, effectively only 1% of all users would actually be responded to and the rest would get "Port busy" or "not responding" or some such error.

Obviously I am missing something because this is clearly not what is happening so instead of proposing my theories as to why I'd love it if someone could set me straight here or point me to something I could read to clear this up. Thanks much.

3 Answers 3

6

The answer can be found in this wikipedia article:

Applications implementing common services often use specifically reserved, well-known port numbers for receiving service requests from client hosts. This process is known as listening and involves the receipt of a request on the well-known port and reestablishing one-to-one server-client communications on another private port, so that other clients may also contact the well-known service port.

Also, from this article on Berkeley sockets on wikipedia.

When an application is listening for stream-oriented connections from other hosts, it is notified of such events (cf. select() function) and must initialize the connection using the accept() function. Accept() creates a new socket for each connection and removes the connection from the listen queue.

1
  • 60 seconds ahead of me AND you follow up with further information! Nice work. +1. Jul 3, 2011 at 22:56
2

When the client connects, and the TCP server accepts the connection, a new socket is created at the server for communication with this client. The original listening socket continues to listen for new requests, and the new socket is used to send and receive from a particular client. Note that a TCP server with N active clients will have N sockets to read/write for each client, in addition to the main listening socket. All these N+1 sockets are all supposed to be on the same port number (the server's well known port number), but they have different socket file descriptors inside the server code.

Source

1

TCP doesn't work that way. A connection to a port from another system does not mean that port can't receive other connections. From the wikipedia article on TCP:

Arriving TCP data packets are identified as belonging to a specific TCP connection by its sockets, that is, the combination of source host address, source port, destination host address, and destination port.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .