T_HSOCKET

Variables of this type represent a connection handle or a handle of an open socket. Via this handle, data can be sent to or received from a socket. The handle can be used to close an open socket.

Syntax

TYPE T_HSOCKET
STRUCT
    handle     : UDINT;
    localAddr  : ST_SockAddr; (* Local address *)
    remoteAddr : ST_SockAddr; (* Remote endpoint address *)
END_STRUCT
END_TYPE

Values

Name

Type

Description

handle

UDINT

Internal TwinCAT TCP/IP Connection Server socket handle.

localAddr

ST_SockAddr

Local socket address.

remoteAddr

ST_SockAddr

Remote socket address.

The following sockets can be opened and closed via the TwinCAT TCP/IP Connection Server: Listener socket, Remote Client socket or Local Client socket. Depending on which of these sockets was opened by the TwinCAT TCP/IP Connection Server, suitable address information is entered into the localAddr and remoteAddr variables.

Connection handle on the server side

Connection handle on the client side

The function block FB_SocketCloseAll can be used to close all connection handles (sockets) that were opened by a PLC runtime system. This means that, if FB_SocketCloseAll is called in one of the tasks of the first runtime systems (port 801), all sockets that were opened in the first runtime system are closed.

Requirements

Development environment

Target system type

PLC libraries to include (category group)

TwinCAT v3.1.0

PC, or CX (x86, X64, ARM)

Tc2_TcpIp (communication)