4D Internet Commands v16

TCP_Listen

Home

 
4D Internet Commands v16
TCP_Listen

TCP_Listen 


 

TCP_Listen ( ipAddress ; remotePort ; localPort ; timeout ; tcp_ID ) -> Function result 
Parameter Type   Description
ipAddress  String in Local IP address to listen to or "" to listen to all available addresses
in Remote IP address used (if a variable containing a null string is passed)
remotePort  Integer in *** Parameter ignored ***
localPort  Integer in Local port number, 0 = find an unused port to use
in Used local port number (if 0 passed)
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 ipAddress 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 ipAddress parameter contains the IP address used for the connection:

  • You can pass a local address where incoming connections must be carried out.
  • 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 also return the remote IP address used for the connection.

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_LONGINT(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



See also 

Appendix B, TCP Port Numbers
TCP_Open
TCP_State

 
PROPERTIES 

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

 
HISTORY 

Modified: 4D Internet Commands 6.8.1

 
ARTICLE USAGE

4D Internet Commands ( 4D Internet Commands v16)