7

I am trying to understand the Three way handshake in the TCP connection setup. My book states, the client first contacts the server, say we want an HTTP connection, so it sends a SYN to port 80. (1)

The server then replies a SYN ACK package. (Here is my question) (2)

And now the client sends a final ACK. (3)

In the book the graphic shows, that (2) goes from the server socket back to the initial client scocket . Then the graphic shows that (3) goes from the client socket to a "Welcoming Socket". The welcoming socket is not the same as the connection socket from (2).

I have downloaded the http.cap from the Wireshark wiki and am taking a look at the initial 3 packets. Here we have the SYN with port 3372 -> 80 then a SYNACK 80 -> 3372 and finaly ACK 3372 -> 80 (with potential Data already).

What confuses me is that the final ACK also goes to port 80 on the server. I thougth that we had created a new Welcoming Socket with a new port, such that the Connection Socket with port 80 can continue listening for new connections.

  • Marqin's answer is correct - whatever book you're reading is talking about Unix/Posix/Linux sockets, not the TCP connections underpinning them. In TCP, it's just: (1) [IP1,port1]->[IP2,port2]+SYN+seq(1); (2) [IP2,port2]->[IP1,port1]+SYN+seq(2)+ACK(seq(1)); (3) [IP1,port1]->[IP2,port2]+ACK(seq(2))+seq(1+1) – Ross Patterson Jan 28 '16 at 15:08
5

Your book is talking about system interface for sockets, which is a bit different from real TCP socket.

TCP RFC doesn't say about "welcoming socket".

So, let's look at definitions. From RFC:

The "three-way handshake" is the procedure used to establish a connection.

So, what is connection?

connection - A logical communication path identified by a pair of sockets.

Ok, so now we need know what is socket. Found:

socket - An address which specifically includes a port identifier, that is, the concatenation of an Internet Address with a TCP port.

So TCP socket is just a pair <address, port> which can accept connections, which need to be established with three-way handshake. Which is send between those two sockets ( and because port is part of socket, there is no welcoming port ).

So what is this "welcoming socket"?

Most systems ( eg. Linux ) uses a little more abstract model, that's made to be easier to use for programmers. ( So we don't have to write to the same structure for every connection. )

First we create abstract socket that represents our server addr/port ( the so called welcoming socket ), and then, when someone connects to it, we get ( via accept() ) from our OS an abstract socket that represents our connection between client and server.

It does cause some misunderstandings...

4

The socket returned from accept keeps the same port you were listening on originally.

Only the full (client address:port, server address:port) 4-tuple needs to be unique, and the client end is already unique, so the server doesn't need to waste an ephemeral port number.

As an aside, this also makes it much easier to see, eg. all your HTTP sockets using netstat, since they'll all have an 80 in the port.

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.