I am new to TCP and trying to wrap my head around it. I understand the basics, e.g. the three-way handshake to establish a connection, followed by application-to-application commands.

My question is: When does the client indicate to the server which application it wants to communicate with. Let's say a server is listening on port 80 for HTTP connections, and I try to ftp into port 80. Is it:

1st) Client sends SYN request to server, which responds to with SYN-ACK. Client responds with SYN, connection established.

2nd) Client sends "retrieve ftp://joe.com/file" command to server.

3rd) Server says "I dont have ftp server application, error." Connection terminated and error on client side.

Or, is the desired application/protocol somehow communicated prior to the threeway handshake and the establishment of a connection?

  • 1
    tls connections can negotiate application protocols as part of the tls handshake using ALPN (which takes place on top of TCP - which has no signaling other than convention about what port runs what service) – Patrick McManus Jul 20 '16 at 19:39
  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you can post and accept your own answer. – Ron Maupin Dec 21 '20 at 18:05

There isn't really any signalling of the requested application in TCP. The application is implied by the destination port number. A web server would open a listening TCP socket on port 80. A client wishing to connect to the web server would open a connection to port 80 and then send HTTP commands. If a misconfigured client connected to port 80 expecting an FTP server it would send FTP commands and these would get passed to the web server application the same, it would be up to the web server application to handle the error and to terminate the connection.

  • Thanks a lot, this is what I thought but wasn't sure if there was some protocol information (other than port) communicated before/during the handshake. – Jimmy Jul 20 '16 at 18:15

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.