Function BlockTcpListenPLCopen motion icon

Description

This function block creates a new socket by performing the bind and listen operations using default TCP settings. You will have to use the TcpClose function block to release the socket returned by TcpListen.

Figure 8-222: The TcpListen function block

Related Functions

TcpAccept, TcpBinReceive, TcpBinSend, TcpClose, TcpConnect, TcpIsConnected, TcpIsValid, 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 listen for socket connections
  Data Type BOOL
  Range 0, 1
  Unit N/A
  Default
Port Description The network port to use
  Data Type DINT
  Range N/A
  Unit N/A
  Default
Backlog Description The size of the queue for pending connections. If more than Backlog number of connection attempts are made prior to a TcpAccept call, then the controller may refuse the connections.
  Data Type DINT
  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
ListenID Description The ID of the new listen socket
  Data Type UDINT

Example

Structured Text

(* TcpListen example *)
CASE StepCounter OF
0:
  Inst_TcpListen(TRUE, 1234, 2);
  StepCounter := StepCounter + 1;
1:
  Inst_TcpListen(TRUE, 1234, 2);
  IF Inst_TcpListen.Done THEN
     MyListenID := Inst_TcpListen.ListenID;
     Inst_TcpListen(FALSE, 0, 0);
     StepCounter := StepCounter + 1;
  END_IF;
END_CASE;