Sample02: “Echo“ client /server

This sample is based on the functionality offered by the former TcSocketHelper.Lib, which is now part of Tc2_TcpIp library. It realizes a Client/Server PLC application based on the functionality provided by the former SocketHelper library.

The client cyclically sends a test string (sToServer) to the remote server. The server returns the same string unchanged to the client (sFromServer).

Sample02: “Echo“ client /server 1:

System requirements

Project downloads

https://github.com/Beckhoff/TF6310_Samples/tree/master/PLC/TCP/Sample02

Project information

The default communication settings used in the above samples are as follows:

To test the client and server application on two different PCs, you have to adjust the port and the IP address accordingly.

However, you can also test the client and server samples with the default values on a single computer by loading the client application into the first PLC runtime system and the server application into the second PLC runtime system.

The behavior of the PLC project sample is determined by the following global variables/constants.

Constant

Value

Description

PLCPRJ_MAX_CONNECTIONS

5

Max. number of server → client connections. A server can establish connections to more than one client. A client can establish a connection to only one server at a time.

PLCPRJ_SERVER_RESPONSE_TIMEOUT

T#10s

Max. delay time (timeout time) after which a server should send a response to the client.

PLCPRJ_CLIENT_SEND_CYCLE_TIME

T#1s

Cycle time based on which a client sends send data (TX) to the server.

PLCPRJ_RECEIVER_POLLING_CYCLE_TIME

T#200ms

Cycle time based on which a client or server polls for receive data (RX).

PLCPRJ_BUFFER_SIZE

10000

Max. internal buffer size for RX/TX data.

The PLC samples define and use the following internal error codes:

Error code

Value

Description

PLCPRJ_ERROR_RECEIVE_BUFFER_OVERFLOW

16#8101

The internal receive buffer reports an overflow.

PLCPRJ_ERROR_SEND_BUFFER_OVERFLOW

16#8102

The internal send buffer reports an overflow.

PLCPRJ_ERROR_RESPONSE_TIMEOUT

16#8103

The server has not sent the response within the specified timeout time.

PLCPRJ_ERROR_INVALID_FRAME_FORMAT

16#8104

The telegram formatting is incorrect (size, faulty data bytes etc.).

The client and server applications (FB_ServerApplication, FB_ClientApplication) were implemented as function blocks. The application and the connection can thus be instanced repeatedly.