TCP/IP: ITcIoTcpProtocol(Recv)
The ITcIoTcpProtocol and ITcIoTcpProtocolRecv interfaces enable TCP/IP communication from the real-time environment.
A project that uses this interface contains a pointer to an ITcIoTcpProtocol object and implements ITcIoTcpProtocolRecv itself. ITcIoTcpProtocolRecv serves as a callback interface for receiving data and events from the TCP/IP module within the application. The interfaces are based on a socket API.
Before a socket can be used, it must be allocated with AllocSocket().
ITcIoTcpProtocolRecv methods:
Name | Description |
---|---|
Is called by the TCP/UDP RT module as a callback to transfer data. | |
Is called by the TCP/UDP RT module as a callback if an event has occurred. |
ITcIoTcpProtocol methods:
Name | Description |
---|---|
Allocates a socket. | |
Enables a socket. | |
Establishes a connection to a remote terminal. | |
Indicates whether a socket is connected (for inbound and outbound connections). | |
Closes a socket. | |
Opens a TCP port for incoming connections (see remarks). | |
For server functionality: Accepts incoming connections (see remarks). | |
Sends data (server and client functionality). | |
Must be called cyclical; ReceiveEvent and ReceiveData are used as callback in the context of this method (server and client functionality). | |
Returns the remote IP address of a communication partner. | |
Returns the number of free bytes in the TCP send buffer. |
Call CheckReceived() continuously. |
Perhaps call AllocSocket() again in the event of an OnlineChange, in order to refresh the callback target. |
The client and server implementation process is described here, independent of programming languages.
Only an overview is provided; the samples illustrate the application.
Implementation of an TCP server:
Name | Description |
---|---|
Opens a socket. | |
Opens a port on which connections are expected. | |
Is called in the ReceiveEvent() method in order to accept a connection. | |
Is called when data are received. | |
Can be used to send data. | |
On the Listen socket and all connection sockets for stopping. |
Code diagram for accepting a connection:
HRESULT CIpStackDemo::ReceiveEvent(ULONG socketId, TCPIP_EVENT tcpEvent)...
case TCPIP_EVENT_CONN_INCOMING:
m_spTcpProt->Accept(socketId);
break;
Implementation of a TCP client:
Name | Description |
---|---|
Opens a socket. | |
Starts connection establishment. | |
Checks whether the connection was established successfully. | |
Is called when data are received. | |
Can be used to send data. | |
On the Listen socket and all connection sockets for stopping. |
Disconnection by the operating system in Promiscuous mode If Promiscuous mode is active at the RT Ethernet adapter in the “Adapter” tab, any TCP connection attempts are blocked by the operating system, since it does not recognize a port opened in the TCP/UDP RT object. |
- Method ITcIoTcpProtocolRecv:ReceiveData
- Method ITcIoTcpProtocolRecv:ReceiveEvent
- Method ITcIoTcpProtocol:AllocSocket
- Method ITcIoTcpProtocol:FreeSocket
- Method ITcIoTcpProtocol:Connect
- Method ITcIoTcpProtocol:IsConnected
- Method ITcIoTcpProtocol:Close
- Method ITcIoTcpProtocol:Listen
- Method ITcIoTcpProtocol:Accept
- Method ITcIoTcpProtocol:SendData
- Method ITcIoTcpProtocol:CheckReceived
- Method ITcIoTcpProtocol:GetRemoteIpAddr
- Method ITcIoTcpProtocol:GetFreeSendDataSize