Function BlockTcpAcceptPLCopen motion icon

Description

This function block performs the accept operation using default TCP settings. You will have to use the TcpClose function block to release the socket returned by TcpAccept.


  • It is possible that the socket becomes invalid if an error occurs in the TCP connection after this function block is called. You must use the TcpIsValid function block after TcpSend. If the socket is no longer valid then you must close it by using the TcpClose function block.

Figure 7-207: The TcpAccept function block

Related Functions

TcpBinReceive, TcpBinSend, TcpClose, TcpConnect, TcpIsConnected, TcpIsValid, TcpListen, TcpReceive, TcpSend

Arguments

Input

Execute Description On the rising edgeClosedA rising edge is the transition of a digital signal from low to high. It is also called positive edge accept a new socket connection
  Data Type BOOL
  Range 0, 1
  Unit N/A
  Default
ListenID Description The ID of a server socket returned by the TcpListen function block
  Data Type UDINT
  Range N/A
  Unit N/A
  Default

Output

Done Description If TRUE, then the command completed successfully
  Data Type BOOL
Error Description If TRUE, an error has occurred
  Data Type BOOL
ErrorID Description Indicates the error if Error output is set to TRUE. See the table in Search IndexFile and TCP/IP Function Block ErrorID Output
  Data Type DINT
ID Description ID of a new client socket accepted, or invalid ID if no new connection.
  Data Type UDINT

Example

Structured Text

(* TcpAccept example *)
CASE StepCounter OF
0:
  Inst_TcpAccept(TRUE, MyListenID);
  StepCounter := StepCounter + 1;
1:
  Inst_TcpAccept(TRUE, MyListenID);
  IF Inst_TcpAccept.Done THEN
     MySocketID := Inst_TcpAccept.ID;
     Inst_TcpAccept(FALSE, 0);
     StepCounter := StepCounter + 1;
  END_IF;
END_CASE;