Principle Governing Socket Operation
(Original Document)
Introduction
The socket is the basic element of TCP communication. It is the socket which transports data.
The TCP/IP function library only provides sockets for flow management and connection between two devices.
NOTE: The TSX ETY 5103 Premium architecture can support up to 64 sockets. They can be used as listening (server) sockets or connected (client) sockets. In a server application, at least 1 socket must be a listening socket. There are no other hard boundaries with respect to the number of client connections versus server connections.
A socket can be created by either the FCT_SOCKET function or the FCT_ACCEPT function. The function returns a number that is used to access the socket.
Establishing a Server Connection
The following table describes the different steps that need to be created on the server in order to establish a connection.
Step
Action
1
Create a socket using the FCT_SOCKET function
2
Associate the created socket with an address (Port number and IP address) using the FCT_BIND function.
3
Set up the socket to accept connections using the FCT_LISTEN function.
Note: the PLC acts as TCP server, the initial socket listens, and receives client socket connections.
4
Apply the FCT_ACCEPT function to this socket to create a new socket which will establish the connection.
Note: this new socket is then connected to the client socket, and its number is returned by the FCT_ACCEPT function. The initial socket is then freed for other clients which wish to connect to the server.
Establishing a Client Connection
The following table describes the different steps that need to be created on the client in order to establish a connection.
Step
Action
1
Create a socket using the FCT_SOCKET function block. The block returns a socket number which can then be used in the subsequent function blocks.
2
Use FCT_CONNECT to make a connection to another Ethernet device by specifying its IP address and the particular port that you are going to communicate on.
Exchanging Data over a TCP Connection
Once a connection has been established, data can be transferred. Transfers are carried out using the FCT_SEND and FCT_RECEIVE functions. The diagram below shows how these exchanges work.
Managing Sockets
Other functions can be used to act on sockets: