# TCP/IP Client

Creates a TCP client which connects to the TCP server at the port and address configured.

Note:

If you have already created and connected to a TCP/IP device (Client and/or Server), and then want to deploy the project to a new environment that has another TCP/IP device with different configuration options, the TCP/IP device will have a broken link icon beside it.

1. To use the new device, from the Project Explorer, right-click on the TCP/IP device and select Reconnect.

2. This will launch the Parameter Configuration dialog, which will allow you to reconfigure the settings accordingly (allowing you to retain any previously constructed scripts).

Control | Description
--- | ---
Remote Address | The IP Address of the TCP Server.
Port | Specifies the port number over which to communicate; this TCP port must be open across all firewalls in order to work.
Packet Splitter | The method to use (and options) to automatically detect packet structure. Open the Packet Splitter Configuration to determine how to detect / split received TCP packets based on an expected format using start and/or end byte sequence to frame a message. Option: None: packets will remain in raw format with no changes made. CRLFTerminator: Carriage Return / Line Feed characters will be at the end of each packet. CRTerminator: Carriage Return character will be at the end of each packet LFTerminator: Line Feed character will be at the end of each packet. NullTerminator: Null character will be at the end of each packet. Custom: The bytes defined by the "Start of Frame" property will be at the start of each packet. The bytes defined by the "End of Frame" property will be at the end of each packet. Deframe Incoming: If checked, incoming packets will be buffered and the OnDataReceived event will only be triggered when a complete packet matching the format Option is found. If the Option is Custom and both Start of Frame and End of Frame have been defined, any data in the buffer found prior to the Start of Frame bytes will be discarded. Frame Outgoing: If checked - outgoing packets will have bytes added to the start/end of each packet matching the format Option selected. Start of Frame: Byte sequence that should be at the start of each packet. Expected format is hex bytes separated by hyphens. (For example, "01-12-0A-FF") End of Frame: Byte sequence that should be at the end of each packet. Expected format is hex bytes separated by hyphens. (For example, "01-12-0A-FF")
Buffer Size | Specifies the size (minimum 1 byte, maximum 67108864 bytes; default = 8192) of the received data buffer for the TCP client device. The buffers are used to queue incoming messages. For example, if the Receive Data block is being used in a Task, and the block executes after the message was actually received, the message will be stored in the buffer, and processed the next time the block executes. Note: This setting can be used in conjunction with the Receive Data block.
Number of Buffers | Specifies the number of buffers (minimum 1 buffer, maximum 65536 buffers; default = 10) for the received data for the TCP client device. Note: This setting can be used in conjunction with the Receive Data block.
Interval (minutes) | The number of minutes between Keep-Alive packets being sent to the server.

Events

TCP Client hooks into the OnDataReceived event.

Before invoking the OnDataReceived method, ensure that if you transmit ASCI text, all data sent and received must be ASCI text and both sender and receiver must be using the same encoding algorithm. Sending or receiving non-ASCI text may result in data loss and unexpected results.

Event | Description
--- | ---
OnDataReceived | This event triggers when Designer receives data from the server. If PacketSplitter is configured, this will only trigger when the received data matches the expected configuration as defined by the Packet Splitter Option. There are two parameters: string data, which encodes the raw binary data based on the encoding format chosen for the device byte[] dataRaw, which is the raw binary data received
OnRawDataReceived | This event triggers when Designer receives data from the server. There are two parameters: string data, which encodes the raw binary data based on the encoding format chosen for the device byte[] dataRaw, which is the raw binary data received
OnConnected | This event triggers when the client establishes the connection with the server. NB In development mode the OnConnected will re-fire upon entering test mode. Supports the parameter TcpClient internalClient, which is the underlying object. Typically not required, but can be useful for setting advanced parameters through the internalClient.Client.SetSocketOption() function.
OnDisconnected | This event triggers when the server explicitly closes the connection

Methods

The TCP/IP Client has two methods:

Method | Description
--- | ---
Send (message) | Sends a message to the client's server.
Flush () | Flushes all buffers of the device by script. This method can be used to consume the device's buffers if it is not consumed otherwise (e.g. an attached Receive Data block).