TCP-IP Management functions
The following functions enable management of TCP-IP sockets for building client or server applications over ETHERNET network:
Functions |
Description |
tcpAccept |
Accept a client connection. |
tcpClose |
Close a socket. |
tcpConnect |
Create a client socket and connect it to a server. |
tcpIsConnected |
Check if a client socket is connected. |
tcpIsValid |
Check if socket is valid. |
tcpListen |
Create a listening socket. |
tcpReceive |
Receive characters. |
tcpReceiveArray |
Receive characters using array. |
tcpSend |
Send characters. |
tcpSendArray |
Send characters using array. |
Each socket is identified in the application by a unique handle manipulated as a DINT value.
|
|
tcpListen: create a listening server socket
SOCK := tcpListen (PORT, MAXCNX);
PORT : DINT TCP port number to be attached to the server socket.
MAXCNX : DINT maximum number of client sockets that can be accepted.
SOCK : DINT ID of the new server socket.
This functions creates a new socket performs the bind and listen operations using default TCP settings. You will have to call the tcpClose function to release the socket returned by this function.
tcpAccept: accept a new client connection
SOCK := tcpAccept (LSOCK);
LSOCK : DINT ID of a server socket returned by the tcpListen function.
SOCK : DINT ID of a new client socket accepted, or invalid ID if no new connection.
This functions performs the accept operation using default TCP settings. You will have to call the tcpClose function to release the socket returned by this function.
tcpConnect: create a client socket and connect it to a server
SOCK := tcpConnect (ADDRESS, PORT);
ADDRESS : STRING IP address of the remote server.
PORT : DINT desired port number on the server.
SOCK : DINT ID of the new client socket.
This functions creates a new socket performs the connect operation using default TCP settings and specified server address and port. You will have to call the tcpClose function to release the socket returned by this function.
|
It is possible that the functions returns a valid socket ID even if the connection to the server is not yet actually performed. After calling this function, you must call tcpIsConnected function to know if the connection is ready. |
tcpIsConnected: test if a client socket is connected
OK := tcpIsConnected (SOCK);
SOCK : DINT ID of the client socket.
OK : BOOL TRUE if connection is correctly established.
|
It is possible that the socket becomes invalid after this function is called, if an error occurs in the TCP connection. You must call the tcpIsValid function after calling this function. If the socket is not valid anymore then you must close it by calling tcpClose. |
tcpClose: release a socket
OK := tcpClose (SOCK);
SOCK : DINT ID of any socket.
OK : BOOL TRUE if successful.
You are responsible for closing any socket created by tcpListen, tcpAccept or tcpConnect functions, even if they have become invalid.
tcpSend: send characters
NBSENT := tcpSend (SOCK, NBCHR, DATA);
SOCK : DINT ID of the socket.
NBCHAR : DINT number of characters to be sent.
DATA : STRING string containing characters to send.
NBSENT : DINT number of characters actually sent.
It is possible that the number of characters actually sent is less than the number expected. In that case, you will have to call again the function on the next cycle to send the pending characters.
|
It is possible that the socket becomes invalid after this function is called, if an error occurs in the TCP connection. You must call the tcpIsValid function after calling this function. If the socket is not valid anymore then you must close it by calling tcpClose. |
tcpReceive: receive characters
NBRCV := tcpReceive (SOCK, MAXCHR, DATA);
SOCK : DINT ID of the socket.
MAXCHR : DINT maximum number of characters desired.
DATA : STRING string where to store received characters.
NBRCV : DINT number of characters actually received.
It is possible that the number of characters actually received is less than the number expected. In that case, you will have to call again the function on te next cycle to receive the pending characters.
|
It is possible that the socket becomes invalid after this function is called, if an error occurs in the TCP connection. You must call the tcpIsValid function after calling this function. If the socket is not valid anymore then you must close it by calling tcpClose. |
tcpIsValid: test if a socket is valid
OK := tcpIsValid (SOCK);
SOCK : DINT ID of the socket.
OK : BOOL TRUE if specified socket is still valid.
tcpReceiveArray: receive characters using array
NBRCV := tcpReceiveArray (SOCK, MAXCHR, DATA);
SOCK : DINT ID of the socket.
MAXCHR : DINT maximum number of characters desired.
DATA[] : USINT[] where to store received characters.
NBRCV : DINT number of characters actually received.
tcpSendArray: send characters using array
NBSENT := tcpSendArray (SOCK, NBCHR, DATA);
SOCK : DINT ID of the socket.
NBCHR : DINT maximum number of characters to be sent.
DATA[] : USINT[] array to be sent.
NBSENT : DINT number of characters actually sent.
TCP-IP Management functions |
IEC 61131-3 Automation platform > Programming - Reference guide > Advanced operations > TCP-IP Management functions |
Created with the Personal Edition of HelpNDoc: Revolutionize Your Documentation Output with HelpNDoc's Stunning User Interface