TCP Server

Use TCP Server in conjunction with the Message Composer for applications that require a proprietary Ethernet communication protocol. Do not use this feature with communication protocols such as MODBUS, or any protocol with built-in support.

The CPU can simultaneously support up to 32 TCP server/client and UDP sockets.

If: x = the number of TCP servers, y = the number of TCP clients, and z = the number of UDP clients, then
x+y+z ≤ 32

Note that you can define up to 4 TCP Servers.

TCP Server is dynamic in nature. Each Server can handle up to 16 simultaneous connections.

How it works

  1. The Server receives a Connect request from a client device.

  2. The TCP server allots a temporary ID number. This number is linked to the device's IP address.

  3. The TCP Server opens a socket and establishes the connection.

  4. When the client disconnects, TCP server closes the socket.
    Now that ID number is free and may be allotted to another client. Allotment is random.

How to Send and Receive Messages

Step 1. Configuring the Controller to function as a TCP Server

Set up Ethernet Addressing

  1. On the Program Navigation tree, click PLC Communications>Physical>CPU Ethernet.

  2. In the Properties Window, click the individual fields to enter the correct parameters.

    CPU IP Address


Configure the Server

  1. On the Program Navigation tree, click PLC Communications>Physical>CPU Ethernet>TCP Servers.

  2. Click Add New.

  3. Define a port: click the fields to name the server, assign a port, set the Number of Connections, and check Keep Alive.

Notes

  • Connections: This sets the number of possible simultaneous connections. The maximum is 16.

  • Keep Alive: This function causes the server to check if a client is still actively connected. If not, the server closes the relevant socket. This will free the socket from a client that suffers a failure or communication error, and that does not disconnect properly.

TCP Server1

The TCP Server Struct

When you configure a TCP Server, UniLogic automatically creates a supporting Global operand struct.

Name

Data Type

Description

Comments

Is Initialized

Bit

Server is initialized.

 

Port Number

UINT32

Displays the number of the Port of the server, as defined in the CPU Ethernet settings.

 

Connection Array (Client ID)

Bit Array

This is a 16 bit array where each bit is linked to a Connection ID. When a connection is established, the relevant bit will turn ON.
If, for example, 4 clients are connected to the server, Connection Array bits 0-3 are ON. When a fifth client connects,  Connection Array (Client ID) bit 4 turns ON, the fourth register in Client's IP Address contains the new client's IP, and fourth register in Client's Port Number contains the new client's port number.
When the fifth client disconnects from the server, all of these values initialize, and the ID is free to be assigned to a new client.

 

Client's IP Address

UINT32 Array

This is an array comprising 16 UINT32 operands. When the server receives a Connect request from a client, the client's IP address is stored in this array.

The position of the IP address in this array is identical to the bit that is turned ON.

 

Client's Port Number

UINT32 array

This is an array comprising 16 UINT32 operands. When the server receives a Connect request from a client, the client's port number is stored in this array.

 

TX Success Counter

UINT32 array

The number of packets sent successfully  per connection

 

TX Fail Counter

UINT32 array

The number packets that failed to be sent per connection

 

RX Success Counter

UINT32 array

The number of packets successfully received  per connection

 

RX Drop Length Error

UINT32 array

Dropped packets per connection, due to insufficient buffer size (user buffer)

 

 

 

TCP/IP Ladder Functions

These include:

UDP Tx

UDP Rx

TCP Server Tx

TCP Server Rx

TCP Server Disconnect

TCP Client Tx

TCP Client Rx

TCP Client Connect

 

TCP Client Disconnect

Ping

 

Related Topics

Communications

Communications: COM Ports and DataCom

PC-PLC COM

Downloading/Uploading a project

MODBUS

Windows XP: USB Driver

Protocols: Third-party

Protocol Third-party Functions