TcpServer.Accept (METH)
METHOD Accept : ERROR_ID
Method Accept is called until an incoming connection is hand over from TCP stack
VAR
fbTcpServer : TcpServer; (* Instance of server function block*)
fbTcpConnection : TcpConnection; (* Instance of Tcp connection with remote device *)
eErrorId : AC500_Tcp.ERROR_ID; (* Error Id of the Connect method *)
dwAddErrNo : AC500_Tcp.RTS_IEC_RESULT; (* Additional error number - list available in GVL of CmpErrors.Erros library *)
hSocket : AC500_Tcp.RTS_IEC_HANDLE; (* Handle to socket of the remote device *)
stSocketAddrExt : AC500_Tcp.SysSocket2.SOCKADDRESS; (* Socket address of external connected remote device *)
END_VAR
------------
// Call of TcpServer.Accept must run cyclically get incoming connections
eErrorId := fbTcpServer.Accept( AddErrNo => dwAddErrNo,
Socket => hSocket,
SocketAddrExt => stSocketAddrExt);
// As long as BUSY, the server is waiting for an incoming connection
IF eErrorId <> AC500_Tcp.ERROR_ID.NO_ERROR THEN
fbTcpConnection.SetIntSocketAddr( SockAddrSetByExternal := ADR(stSocketAddrExt)); // Assign socket address information to TcpConnection instance
fbTcpConnection.Socket := hSocket; // Assign socket handle to TcpConnection instance
; // Continue with next steps to receive or send data via the fbTcpConnection instance
// If eErrorId does neither has NO_ERROR nor BUSY, an error is pending
ELSIF eErrorId <> AC500_Tcp.ERROR_ID.BUSY THEN
; // For ERR_INTERNAL, please check AddErrNo - AC500_Tcp.RTS_IEC_RESULT - the error codes are listed in the GVL of CmpErros.Errors
END_IF
- InOut:
Scope
Name
Type
Comment
Return
AcceptOutput
AddErrNoRTS_IEC_RESULTAdditional error number gives information about error from SysSock2Close –> please see CmpErrors.Errors
SocketRTS_IEC_HANDLESocket handle of an incoming connection
SocketAddrExtSysSocket2.SOCKADDRESSExternal Socket address of the incoming connection