SOCKET_OPEN
The SOCKET_OPEN instruction opens the connection for the specified destination address for Transmission Control Protocol (TCP) connections. For User Datagram Protocol (UDP) connections, associates a destination IP address and port number with the specified socket.
Operations details:
- For User Datagram Protocol (UDP) connections usingSOCKET_OPEN, the IP address and port number are not required each time data is sent.
- For UDP connections not usingSOCKET_OPEN, the destination address must be specified each timeSOCKET_WRITEis used to send data.
- When usingSOCKET_READ, in addition to receiving data, the address of the sender is returned. The senders address can be used to send a response usingSOCKET_WRITE.
- ASOCKET_OPENoperation might return before the timeout period without creating a Transmission Control Protocol (TCP) connection. This might occur if the destination device is running but is not listening for connections on the specified port number.SOCKET_OPENreturns with an error before the timeout period.
- Outputs update synchronously from the program scan.
Languages supported: Function block diagram, ladder diagram, structured text.
This instruction applies to the L20E, L50E, and L70E controllers.
SOCKET_OPEN

Parameter | Parameter Type | Data Type | Description |
---|---|---|---|
Execute | Input | BOOL | Instruction block enable.
|
Instance | Input | UDINT | Copy from the returned Socket Handler from a SOCKET_CREATE function block. |
Timeout | Input | UDINT | Timeout for SOCKET_OPEN function block. The function block returns an Error if the Timeout value is less than the minimum value. Timeout range: 1000-1800000 milliseconds Set Timeout to 0 to use the default value 10000 (10 Second). |
DestAddr | Input | The address of the destination connection. A connection between the IP address and the port number of remote host is required. The following IP Addresses are not supported for DestAddr:
Example for IP Address of 192.168.2.100 and Port 12000:
| |
EnUDPRxFilter | Input | BOOL | For UDP socket, when SOCKET_OPEN and Enable EnUDPRxFilter are used, a packet filter for specific IP address and port number is not needed each time to read data.
EnUDPRxFilter Disabled:
|
Done | Output | BOOL | Indicates when operation is complete.
Output is updated synchronously from the program scan. |
Busy | Output | BOOL |
Output is updated synchronously from the program scan. |
Error | Output | BOOL | Indicates an error occurred.
Output is updated synchronously from the program scan. |
Status | Output | SOCK_STATUS | Status is defined using the SOCK_STATUS data type which contains ErrorID, SubErrorID, and StatusBits information. Output is updated synchronously from the program scan. |
SOCKET_OPEN examples
SOCKET_OPEN function block diagram example

SOCKET_OPEN ladder diagram example

SOCKET_OPEN structured text example

Results - TCP

Results - UDP

Provide Feedback