1

With TCP you listen to some port (say port 80) and then when an incoming connection pops up, you accept it, establishing the connection over a new port.

Why is this necessary? Why can't you just keep communicating over the original port?

  • Only one application can use any port at any one time. That means that if an application binds to port 80, another application that needs TCP will need to use a different port. You are running many applications at the same time, and any that use TCP each need to use a different port. – Ron Maupin Nov 19 '17 at 21:40
  • @RonMaupin: Yeah, that wasn't what I was asking though. I was apparently just misunderstanding what is actually happening. – user541686 Nov 19 '17 at 21:46
  • You should look at RFC 793, Transmission Control Protocol, Section 1.5 Operation, especially the parts about multiplexing and connections. – Ron Maupin Nov 19 '17 at 22:18
  • You may be thinking of the diffrence between a app like a web server vs the computer connecting for example. A web page that is http will usually be port 80. I just went to ipchicken.com and the port my browser used on my end was 19129. I refreshed the page and it used 22913. My side changes but the web page stays port 80. Being able to have many "streams of communication" using one ip address is a huge benefit. A web server for example can send data to many "devices" with one ip address on diffrent ports. I picture a hose with 65535 little hoses in it. – Fixitrod Nov 20 '17 at 3:35
2

The incoming connection is accepted and the socket uses the listening port on the server, not an another one. Some protocols are more complicated than that but HTTP (from your question's port 80) isn't.

| improve this answer | |
  • +1 wow I can't believe I missed this. Somewhere I got the impression there was a new port being used but I guess I was wrong. Thanks! – user541686 Nov 19 '17 at 21:45
  • 1
    One reason for confusion is that the TCP RFC uses a different definition of the term "socket" from the one used in modern network programming. – Peter Green Nov 20 '17 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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