3

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.

john-13-14
  • 41
  • 1
  • 1
  • 3
  • 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 08 '14 at 18:23

2 Answers2

4

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.

EEAA
  • 108,414
  • 18
  • 172
  • 242
2

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 :)

Chopper3
  • 100,240
  • 9
  • 106
  • 238
  • 1
    Its not *that* simple. The server isn't just echoing packets. It receives a packet; routes it to whatever process and socket it is intended for; the *process* sends a response back down the same socket; and the OS sends it to the associated destination. – user207421 Sep 27 '16 at 00:03