TCP UDP: Transmission of Data Over the Internet

chief information officer job descriptionTCP (transmission control protocol) and UDP (user datagram protocol) are the two main communication protocols used on the Internet. They are both similar in some ways, but each has a different use based on reliability, speed and bandwidth. TCP/IP is the most common transmission language used, but some of the common applications you use transmit UDP packages instead. If you’re planning to program network application, you need to know both transmission protocols.

New to network programming? Learn the TCP/IP protocol suite at Udemy.com.

TCP/IP and Internet Communication

TCP/IP is a suite of protocols, but since it’s used across the Internet, it’s the most important to understand. The IP part of the protocol is what you know as the address for your computer. Every computer on the network must have a unique IP address. Some IP ranges don’t route, which means that your local network IP is different than what is seen as the transmission passes from your router to the web server.

The TCP part of the protocol suite is the transmission part of the protocol. TCP determines how your data packets travel along a wire. This wire could be your internal network or across the Internet to a web server. First, TCP is a connection-oriented protocol. This means that a handshake occurs between your computer and the destination server. Your computer sends a message that basically says “hello” or the SYN request. The server responds with an acknowledgement or ACK and your computer then acknowledges the response and a connection is made.

Do a TCP deep dive and get a better understanding of TCP/IP programming at Udemy.com.

The TCP protocol then chops up your data into packets. These packets contain the source IP address, the server or destination IP address, the data, the packet’s sequence number (to later build the full message when it reaches the server), the source port number, the destination port and several other options. Because the connection is reliable, there is a checksum and error checking ensures that the entire message reaches the destination. TCP is more bandwidth intensive than UDP, so it takes up more resources than UDP.

You probably recognize the HTTP protocol. This is the most common example of TCP. TCP is also used in HTTPS, FTP, SMTP and Telnet connections. If you create a network application, you’ll need to understand this protocol but most frameworks include a library you can use to communicate with TCP and IP.

UDP and Connectionless Communication

User datagram protocol uses a somewhat similar setup. This protocol also sends messages in packets, but these packets are not sent after a handshake. This means that the connection isn’t as reliable. UDP is considered a connectionless transfer. You send data packets across the wire, but your computer is not interested in any confirmation. Consider TCP like a phone connection. You call someone and this someone acknowledges your phone call. After confirmation, you then begin your conversation. This is your typical TCP communication.

With UDP, you have no confirmation. Instead, you can consider UDP like a conversation using text message. You send a text message and you don’t know if the recipient gets the message. You can continue your conversation without any confirmation from your recipient. The only way you know that the recipient received your message is if he sends you a message. His message isn’t confirmed either unless you then send a message back. Both of you could send messages and have a conversation without either of you receiving a confirmation, but you can still communicate. This is similar to the UDP protocol.

As a matter of fact, UDP is used in similar concepts. UDP is often used in chat programs. You send a chat message to a recipient and the only way you know the recipient got your message was if he sends a message back to you. Other transmission protocols use UDP such as DNS, DHCP, TFTP, SNMP, VOIP and RIP.

UDP is not reliable, but it does give you a more lightweight version of the TCP protocol. It’s faster and uses up less bandwidth than TCP. UDP also doesn’t use an order like TCP. With TCP, each packet has a sequence number. When packets reach the server, the server’s network card then puts all of these packets back together to build the message. This message is then what you see on your computer or the server. UDP is different in that there is no sequence with the packets. You can add some kind of sequence arrangement, but the application must handle the sequencing.

UDP packets still have a source and destination port number attached to the packets. Both TCP and UDP need a port number. The port on your computer used to communicate with the server is probably different than the server’s port. Outgoing and incoming ports are set by the application. The server listens on a particular port for your computer’s request. Your computer sends a request on a particular port, the server “hears” your request and then communication happens. These ports are open until communication ends.

Whatever protocol you use is up to you. But this choice will determine the efficiency and reliability of your application. For instance, if you plan to write a network application that connects to the server’s desktop, you probably want to have an application that uses TCP to keep the connection alive and verify that packets are sent successfully. However, if you are creating a web communication application where two users chat with one another, you probably want to use the UDP protocol.

Both of these types are supported in several programming languages. For instance, the C# .NET framework has a library for creating network applications. C++ works well with network libraries. As a matter of fact, most network security applications are written with the C++ language. Even most network hacking and security penetration tools are created using the C++ language.  There are also some open-source libraries for creating TCP and UDP applications.

Want to learn more about TCP and communication over the Internet? Take a look at online Udemy.com courses.