Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a misundertanding about some networking theory and because I couldn't find a definitive answer online (most resourceas are theory and theory etc without concise examples) I'm asking here.

Assuming I have a server with IP 10.10.10.10 that listens on port 80 and two clients with IP 20.20.20.20 and IP 30.30.30.30 respectivelly, when both clients connect to the server on port 80, what happens?

Does it...

A. server accepts connection on port 80 for both clients and creates two sokets:

server IP: 10.10.10.10
server port: 80
client IP: 20.20.20.20
client port: whatever port client 1 used to connect

and

server IP: 10.10.10.10
server port: 80
client IP: 30.30.30.30
client port: whatever port client 2 used to connect

then when new packets arrive on port 80 from the clients they get dispatched to the appropriate socket based on the client IP and port?

Or...

B. server only accepts connections on port 80 and alocates other ports for communication with clients as the clients connect? So now we still have two sockets created but like this:

server IP: 10.10.10.10
server port: random free port
client IP: 20.20.20.20
client port: whatever port client 1 used to connect

and

server IP: 10.10.10.10
server port: another random free port
client IP: 30.30.30.30
client port: whatever port client 2 used to connect

while port 80 remains free to accept other connections?

So which is it?

I'm sorry if the question sounds stupid or newbish but I found both mentioned online and they can't both be true. I'm thinking others have the same confusion and a clear and concice answer here might be very helpful.

share|improve this question

closed as off topic by Rex, Tim Brigham, Michael Hampton Jun 10 '13 at 16:57

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
I'm sorry, but this is WAY off topic for Server Fault - we are not an instructional resource, we are a site for professional system and network administrators seeking answers to actual problems in production environments. To find the answer to your question google rendezvous socket and read up. I also suggest a copy of TCP/IP Illustrated, which has been the standard reference for longer than I've been in the industry. –  voretaq7 Jun 10 '13 at 16:19
    
@voretaq7: sorry if this is inapropriate but although not in production environments I still had my problem. Thanks for the resources... sorry again! –  john-13-14 Jun 10 '13 at 16:27
    
I second the recommendation for TCP/IP Illustrated. –  Jed Daniels Jun 10 '13 at 16:32
    
@john-13-14, you should post this topic inside stackoverflow instead of this serverfault.... missplaced. –  gumuruh Aug 8 at 18:23

2 Answers 2

up vote 1 down vote accepted

Sockets are uniquely identified by the combination of (source ip, source port, destination ip, destination port), so your A scenario is correct.

Take a minute and think through the ramifications if B were the case. Firewalling would be near impossible if the destination port were constantly changing - there would need to be constant communication between the server and network gear, with the server informing the firewall where it's expecting to accept traffic. For this reason and many others, that would be nightmare.

share|improve this answer
    
Now that you mention it it does make sense :) –  john-13-14 Jun 10 '13 at 16:23

It's SO much easier than you think.

The server's listening on say port 80, it gets a packet in from 20.xx so knows that 20.xx wants something so goes and does it and send it back to 20.xx. Then 30.xx comes and asks on port 80 so it responds back directly to 30.xx.

That's it, nothing much more complex.

It's a bit like if you're on the phone and you can hear two different people talking, you can hear you wife ask what time you're back and you can respond with 'five dear' and you can hear your kids screaming for you to bring back ice-cream and say 'no and get to bed' - all down one line. Seriously that's about the best analogy I could think of sorry :)

share|improve this answer

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