lamaPLC Communication: TCP / UDP Basic

The Internet protocol suite, commonly known as TCP/IP, is a framework for organizing the set of communication protocols used in the Internet and similar computer networks according to functional criteria. The foundational protocols in the suite are the Transmission Control Protocol (TCP), the User Datagram Protocol (UDP), and the Internet Protocol (IP). Early versions of this networking model were known as the Department of Defense (DoD) model because the research and development were funded by the United States Department of Defense through DARPA.

The Internet protocol suite provides end-to-end data communication specifying how data should be packetized, addressed, transmitted, routed, and received. This functionality is organized into four abstraction layers, which classify all related protocols according to each protocol's scope of networking. An implementation of the layers for a particular application forms a protocol stack. From lowest to highest, the layers are the link layer, containing communication methods for data that remains within a single network segment (link); the internet layer, providing internetworking between independent networks; the transport layer, handling host-to-host communication; and the application layer, providing process-to-process data exchange for applications.

The technical standards underlying the Internet protocol suite and its constituent protocols are maintained by the Internet Engineering Task Force (IETF). The Internet protocol suite predates the OSI model, a more comprehensive reference framework for general networking systems.

TCP/IP

The TCP/IP (Transmission Control Protocol / Internet protocol) model is the default method of data communication on the Internet. It was developed by the United States Department of Defense to enable the accurate and correct transmission of data between devices. It breaks messages into packets to avoid having to resend the entire message in case it encounters a problem during transmission. Packets are automatically reassembled once they reach their destination. Every packet can take a different route between the source and the destination computer, depending on whether the original route used becomes congested or unavailable.

TCP/IP divides communication tasks into layers that keep the process standardized, without hardware and software providers doing the management themselves. The data packets must pass through four layers before they are received by the destination device, then TCP/IP goes through the layers in reverse order to put the message back into its original format.

As a connection based protocol, the TCP establishes and maintains a connection between applications or devices until they finish exchanging data. It determines how the original message should be broken into packets, numbers and reassembles the packets, and sends them on to other devices on the network, such as routers, security gateways, and switches, then on to their destination. TCP also sends and receives packets from the network layer, handles the transmission of any dropped packets, manages flow control, and ensures all packets reach their destination.

A good example of how this works in practice is when an email is sent using SMTP from an email server. To start the process, the TCP layer in the server divides the message into packets, numbers them, and forwards them to the IP layer, which then transports each packet to the destination email server. When packets arrive, they are handed back to the TCP layer to be reassembled into the original message format and handed back to the email server, which delivers the message to a user’s email inbox.

TCP/IP uses a three-way handshake to establish a connection between a device and a server, which ensures multiple TCP socket connections can be transferred in both directions concurrently. Both the device and server must synchronize and acknowledge packets before communication begins, then they can negotiate, separate, and transfer TCP socket connections.

The 4 Layers of the TCP/IP Model

The TCP/IP model defines how devices should transmit data between them and enables communication over networks and large distances. The model represents how data is exchanged and organized over networks. It is split into four layers, which set the standards for data exchange and represent how data is handled and packaged when being delivered between applications, devices, and servers.

The four layers of the TCP/IP model are as follows:

  1. Datalink layer: The datalink layer defines how data should be sent, handles the physical act of sending and receiving data, and is responsible for transmitting data between applications or devices on a network. This includes defining how data should be signaled by hardware and other transmission devices on a network, such as a computer’s device driver, an Ethernet cable, a network interface card (NIC), or a wireless network. It is also referred to as the link layer, network access layer, network interface layer, or physical layer and is the combination of the physical and data link layers of the Open Systems Interconnection (OSI) model, which standardizes communications functions on computing and telecommunications systems.
  2. Internet layer: The internet layer is responsible for sending packets from a network and controlling their movement across a network to ensure they reach their destination. It provides the functions and procedures for transferring data sequences between applications and devices across networks.
  3. Transport layer: The transport layer is responsible for providing a solid and reliable data connection between the original application or device and its intended destination. This is the level where data is divided into packets and numbered to create a sequence. The transport layer then determines how much data must be sent, where it should be sent to, and at what rate. It ensures that data packets are sent without errors and in sequence and obtains the acknowledgment that the destination device has received the data packets.
  4. Application layer: The application layer refers to programs that need TCP/IP to help them communicate with each other. This is the level that users typically interact with, such as email systems and messaging platforms. It combines the session, presentation, and application layers of the OSI model.

TCP & UDP: Differences between the protocols

The main difference between TCP (transmission control protocol) and UDP (user datagram protocol) is that TCP is a connection-based protocol and UDP is connectionless. While TCP is more reliable, it transfers data more slowly. UDP is less reliable but works more quickly. This makes each protocol suited to different types of data transfers.

Protocols are rules that govern how data is formatted and sent over a network. TCP and UDP are two different methods for doing the same job: transferring data via the internet. They enable servers and devices to communicate so you can send emails, watch Netflix, play games, and browse web pages.

TCP & UDP: Differences between the protocols

TCP creates a secure communication line to ensure the reliable transmission of all data. Once a message is sent, the receipt is verified to make sure all the data was transferred.

UDP does not establish a connection when sending data. It sends data without confirming receipt or checking for errors. That means some or all of the data may be lost during transmission.

Here are the main differences between TCP and UDP:

FactorTCPUDP
Connection typeRequires an established connection before transmitting dataNo connection is needed to start and end a data transfer
Data sequenceCan sequence data (send in a specific order)Cannot sequence or arrange data
Data retransmissionCan retransmit data if packets fail to arriveNo data retransmitting. Lost data can’t be retrieved
DeliveryDelivery is guaranteedDelivery is not guaranteed
Check for errorsThorough error-checking guarantees data arrives in its intended stateMinimal error-checking covers the basics but may not prevent all errors
BroadcastingNot supportedSupported
SpeedSlow, but complete data deliveryFast, but at risk of incomplete data delivery
Best of..- Email or texting
- File transfers
- Web browsing
- Live streaming
- Online gaming
- Video chat

TCP Ports

TCP has something known as a port which is a unique number assigned to different applications. Standard services (applications) have well known ports that are documented:

  • HTTP ➜ 80
  • HTTPS ➜ 443
  • FTP ➜ 21
  • FTPS / SSH ➜ 22
  • POP3 ➜ 110
  • POP3 SSL ➜ 995
  • IMAP➜ 143
  • IMAP SSL ➜ 993
  • SMTP ➜ 25 (Alternate: 26)
  • SMTP SSL ➜ 587
  • MySQL ➜ 3306
  • cPanel ➜ 2082
  • cPanel SSL ➜ 2083
  • WHM (Webhost Manager) ➜ 2086
  • WHM (Webhost Manager) SSL ➜ 2087
  • Webmail ➜ 2095
  • Webmail SSL➜ 2096
  • WebDAV/WebDisk➜ 2077
  • WebDAV/WebDisk SSL ➜ 2078
  • RSTP ➜ 554
  • STP ➜ 128
  • unencrypted MQTT ➜ 1883
  • encrypted MQTT ➜ 8883