TcpAccept

PLCopen motion icon

 Function BlockClosed A function block groups an algorithm and a set of private data. It has inputs and outputs. - Performs the accept operation.

Inputs

Input

Data Type

Range

Unit

Default

Description

Execute

BOOL

0, 1

N/A

No default

On the rising edgeClosed The transition of a digital signal from low to high. AKA: positive edge., accept a new socket connection.

ListenID

UDINT

N/A

N/A

No default

The ID of a server socket returned by the TcpListen functionClosed A function calculates a result according to the current value of its inputs. A function has no internal data and is not linked to declared instances. block.

Outputs

Output

Data Type

Range

Unit

Description

Done

BOOL

 

 

If TRUE, the command completed successfully.

Error

BOOL

 

 

If TRUE, an error has occurred.

ErrorID

DINT

 

 

Indicates the error if Error output is TRUE.

See the table in Search IndexFile and TCP/IP Function Block ErrorIDs.

ID

UDINT

 

 

Either:

  • ID of a new client socket accepted.
  • Invalid ID if no new connection.

Remarks


  • It is possible that the socket becomes invalid if an error occurs in the TCP connection after this function block is called.
    Use the TcpIsValid function block after TcpSend.
    If the socket is no longer valid, close it using the TcpClose function block.
  • This function block performs the accept operation using default TCP settings.
  • Use the TcpClose function block to release the socket returned by TcpAccept.

Figure 1: TcpAccept

FBD Language Example

Not available.

FFLD Language Example

Not available.

IL Language Example

Not available.

ST Language Example

(* 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;

See Also