Exploring the Transport Layer
Pages: 1, 2

Connection oriented and connectionless

Classically, TCP's connection-oriented mechanism is referred to as a "three-way handshake." The TCP protocol has special messages for establishing a connection. These are: synchronization, or SYN which synchronizes sequence numbers in the TCP header; acknowledge, or ACK which makes sure the acknowledgement number is valid; and maximum transmission unit (MTU). When TCP client wants to create a connection with a remote server, it will send a SYN message.

Data transmission diagram.
Figure 2. Connection-oriented and connectionless data transmission examples.

A SYN message is a bit flag in the TCP header. When the SYN flag is set, it means that synchronization is requested with the remote server. The client will send an initial sequence number. Included in this header is also information on the maximum transmission size, or MTU. When the server hears the connection request, the server will respond with a message containing the SYN and ACK bit fields set in the responding TCP header. The header will also contain the sequence number for validation. The client will respond back with an ACK and the sequenced number is incremented by one. This method of TCP connection is called a three-way handshake.

Port numbers and sockets

TCP and UDP run over the IP protocol, which means that both the client and the server are required to use IP addressing. The application too must identify itself to the TCP/IP protocol and this is achieved through 16-bit port numbers. Basically, two styles of port numbers exist. They are, well-known port numbers and ephemeral port numbers.

Well-known port numbers, whose range is 1 to 1023, are managed by the Internet Assigned Numbers Authority. Well-known TCP ports include FTP, port 21; and telnet, port 23. This means a Macintosh using telnet to access a Unix machine will request port 23. Well-known port numbers are reserved across platforms for TCP/IP.

Ephemeral ports are used by clients to establish contact with the server. The client doesn't need a well-known port number. Ephemeral ports are in the range of 1024 to 5000. When writing custom applications for a client-server, port numbers can also be selected from this range. An example of a custom application would be an Internet game that requires sending game update messages to all players. The game server would probably use a port number of 2000 and the clients would use a port number value of 2001.

The TCP/IP protocol requires that the protocol be identified (whether it's TCP or UDP) in the IP header along with source and destination IP addresses. For TCP/IP to communicate with the application, a 6-bit port number is required for the source and destination. These three components are required to establish the virtual circuit. Under the TCP/IP suite this virtual circuit is called a socket.

For the Sprockets network, recall that we have robots working on the manufacturing floor. Our network engineer, Nanna Spacely, is only involved in the assigning of IP addresses for these devices. It is up to the application programmers to assign the proper ports numbers for the client and server applications.

Figure 3. A socket requires an IP address, a port number, and a TCP/IP protocol.

This has been by no means an exhaustive discussion on the powerful TCP/IP protocol suite. A slightly more in-depth document, Understanding TCP/IP, is available at the Cisco Systems "univercd" web site. is also another good site for expanding your knowledge on TCP/IP. This site is also broken into links by network layer model which makes it kind of nice to use.

For the next installation of Networking as a Second Language, we're going to examine an interesting protocol -- multicast! So don't miss out.

Take the pop quiz!

Michael J. Norton is a software engineer at Cisco Systems.

Read more Networking as a 2nd Language columns.

Return to the O'Reilly Network.