Technical introduction

This section will give a general overview about the transport protocols TCP and UDP and will also link to the corresponding PLC libraries needed to implement each protocol. Both transport protocols are part of the Internet Protocol suite and therefore an important part of our everyday communication, e.g. the Internet.

Transmission Control Protocol (TCP)

TCP is a connection-oriented transport protocol (OSI layer 4) that can be compared to a telephone connection, where participants have to establish the connection first before data can be transmitted. TCP provides a reliable and ordered delivery of a stream of bytes, therefore it is considered to be a “stream-oriented transport protocol”. The TCP protocol is used for network applications where a receive confirmation is required for the data sent by a client or server. The TCP protocol is well suited for sending larger data quantities and transports a data stream without a defined start and end. For the transmitter this is not a problem since he knows how many data bytes are transmitted. However, the receiver is unable to detect where a message ends within the data stream and where the next data stream starts. A read call on the receiver side only supplies the data currently in the receive buffer (this may be less or more than the data block sent by the other device). Therefore the transmitter has to specify a message structure that is known to the receiver and can be interpreted. In simple cases the message structure may consist of the data and a final control character (e.g. carriage return). The final control character indicates the end of a message. A possible message structure which is indeed often used for transferring binary data with a variable length could be defined as follows: The first data bytes contain a special control character (a so-called start delimiter) and the data length of the subsequent data. This enables the receiver to detect the start and end of the message.

TCP/IP client

A minimum TCP/IP client implementation within the PLC requires the following function blocks:

TCP/IP server

A minimum TCP/IP server implementation within the PLC requires the following function blocks:

The instances of the FB_SocketAccept and FB_SocketReceive function blocks are called cyclically (polling), all others are called as required.

User Datagram Protocol (UDP)

UDP is a connection-less protocol, which means that data is sent between network devices without an explicit connection. UDP uses a simple transmission model without implicitly defining workflows for handshaking, reliability, data ordering or congestion control. However, even as this implies that UDP datagrams may arrive out of order, appear duplicated, or congest the wire, UDP is in some cases preffered to TCP, especially in realtime communication because all mentioned features (which are implemented in TCP) require processing power and therefore time. Because of its connection-less nature, the UDP protocol is well suited for sending small data quantities. UDP is a “packet-oriented/message-oriented transport protocol”, i.e. the sent data block is received on the receiver side as a complete data block.

The following function blocks are required for a minimum UDP client/server implementation:

The instances of the FB_SocketUdpReceiveFrom function block are called cyclically (polling), all others are called as required.

See also: Samples