sockConnect (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.00 / 1.00.00


Initiates a TCP/IP socket connection to the specified IP address/port number. When this function returns, the connection has not been finally established but only initiated. The establishing of the connection must be determined by using the sockConnection() function block.

It is possible to establish a maximum of 8 simultaneous socket connections.

 

Please note that for each sockConnect() there must be a sockDisconnect(), even if the connection is closed from the "outside" (see example below).

 

Input:

ip : DINT

32 bit IP address to connect to.

 

port : DINT

Port number to connect to an IP address.

 

iface : SINT (default 0)

The network interface to use. 0 = Default network, 1 = Cellular network, 2 = LAN network, etc. (See Network)

Note: For backwards compatibility the cellular network is used as default network.

 

Returns: SINT

ID of the connection. If return value is 0, the connection could not be initiated (possibly because there are too many sockConnect() without corresponding sockDisconnect()).

 

Declaration:

FUNCTION sockConnect : SINT;
VAR_INPUT
   ip    : DINT;       // IP address to connect to
   port  : DINT;       // Port number to connect to
   iface : SINT := 0;  // Interface to connect on
END_VAR;

 

 


Example:

 

Please see the "Examples - Socket Communication"