Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCP's Welcome port vs connection port and the purpose of three way handshake [duplicate]

This is the picture from the textbook James F. Kurose, Keith W. Ross: Computer networking: a top-down approach, ISBN-13: 978-0-13-285620-1. ISBN-10: 0-13-285620-4.

enter image description here

According to the picture, the welcoming port is different to actual connection port.(since different socket is assigned a different port number. So let's say Client is initializing a HTTP request, so the welcoming port is 80 on the web server, and then the actual connection port is different than 80?

The second question is, what's the purpose of handshaking for TCP? I was only taught that why TCP's handshaking is but don't actually know why handshaking is essential. If we get rid of handshaking from TCP, we can still make TCP a reliable data transfer protocol, can't we?

like image 300
whoisit Avatar asked Dec 07 '25 06:12

whoisit


2 Answers

According to the picture, the welcoming port is different to actual connection port.

No it isn't. There is nothing in the picture that indicates that. It indicates that the listening and connected sockets are different. Not the same thing.

(since different socket is assigned a different port number).

No it isn't. An accepted socket has the same local port number as the listening socket it was accepted from. I don't know where you got the term 'welcoming port' from, or the author got the term 'welcoming socket' from. The correct terminology is 'listening port'.

So let's say Client is initializing a HTTP request, so the welcoming port is 80 on the web server, and then the actual connection port is different than 80?

No. It is 80.

The second question is, what's the purpose of handshaking for TCP? I was only taught that why TCP's handshaking is but don't actually know why handshaking is essential. If we get rid of handshaking from TCP, we can still make TCP a reliable data transfer protocol, can't we?

No. It has several purposes, one of which is to establish that both sides know that the connection exists, and another of which is to establish an initial sequence number in each direction, which makes it harder for an attacker to inject data.

like image 183
user207421 Avatar answered Dec 10 '25 11:12

user207421


At the lowest level the "welcoming socket" is a file descriptor that represents the listening socket on a particular port. When another computer connects to that port and the server calls accept then a new file descriptor is generated that represents that specific connection. That's the "connection socket" on this diagram.

The three way handshake is necessary to establish the parameters of the TCP/IP session. TCP/IP is a fairly minimal protocol, there's not a lot of fuss or ceremony. The SYN, SYN-ACK, ACK process ensures that both ends of the connection are in sync before data transfer begins.

This synchronization process quite familiar:

enter image description here

Without that final ACK the party that sent the SYN-ACK doesn't know if their response was received or not. That third packet is necessary to provide confirmation.

like image 36
tadman Avatar answered Dec 10 '25 09:12

tadman