4D v13.2

TCP_Listen

Home

 
4D v13.2
TCP_Listen

TCP_Listen 


 

TCP_Listen ( localAddress ; localPort ; remotePort ; timeout ; tcp_ID ) -> Function result 
Parameter Type   Description
localAddress  String in IP address to listen to or "" to listen to all the addresses availabe
in IP address used (if a variable containing a null string is passed)
localPort  Integer in Local port number, 0 = find an unused port to use
in Used local port number (if 0 passed)
remotePort  Integer in *** Parameter ignored ***
timeout  Integer in # of seconds to wait, 0 = wait forever
tcp_ID  Longint in Reference to this TCP session
Function result  Integer in Error Code

The TCP_Listen command opens a communication "socket" on the port specified by the localAddress and localPort parameters. This command does not return control back to the 4D calling method until either a connection is made or the timeout period has elapsed. Though it may seem as though this would lock up your database until a connection was made, the command is friendly to other 4D processes that may be running. This command will slice time to other 4D processes you may already have running.

Most developers will want to issue this call from a method which has been spawned into its own 4D process (especially if you specify the timeout period to wait forever).

The localAddress parameter contains the local IP address where the incoming connection must be made:

  • If a null string is passed in this parameter, the command listens to all the addresses available on the machine.
  • If a variable containing a null string is passed in this parameter, it will return the IP address used at the end of its execution.

localPort contains the TCP port you wish to use for communication. If you pass a zero as this parameter, the command will find any unused port and pass that number back to this parameter.

timeout specifies the number of seconds this command will wait for an incoming connection. A zero in this parameter will cause the command to wait indefinitely for an incoming connection. Caution should be taken when passing a zero since control will never be returned to the calling 4D process if a connection is never made. Never pass zero to this parameter in a single-process database.

tcp_ID is the long integer reference to the session that was opened. This reference will be used in all subsequent TCP external calls that reference this session.

Any TCP connection opened using the TCP_Listen command must be closed later using the TCP_Close command.

Example  

 C_LONGINT(vTCPID)
 C_INTEGER(vStatus)
 $err:=TCP_Listen("";0;0;30;vTCPID)
 $err:=TCP_State(vTCPID;vStatus)
 If(vStatus=2) `socket is open and listening
    DoSomething
    $err:=TCP_Close(vTCPID)
 End if

 
PROPERTIES 

Product: 4D
Theme: IC TCP/IP
Number: 88932

 
INDEX

Alphabetical list of commands

 
HISTORY 

Modified: 4D Internet Commands 6.8.1

 
SEE ALSO 

Appendix B, TCP Port Numbers
TCP_Open
TCP_State