TCPAccept

Command group Flag affected Reversible Execute on client Platform(s)
External commands YES NO NO All

Syntax

TCPAccept (socketReturns socket

Description

Note: The flag is set according to whether Omnis was able to make a call to this external command.

This Web command is multi-threaded, allowing another thread to execute in the multi-threaded server while it runs. Note that the same socket cannot safely be used concurrently by more than one thread.

You use TCPAccept to accept an incoming connection request from another application.

The Socket parameter is a socket which is listening for incoming connections on a particular port. You must create this socket using TCPSocket, bind a port (and implicitly the local machine’s IP address) to it using TCPBind, and start listening for connections by calling TCPListen, before you can call TCPAccept to accept incoming connections using the socket.

TCPAccept is affected by the blocking state of the Socket parameter. If the Socket parameter is blocking, TCPAccept waits until an incoming connection arrives, and then returns a new Socket for the connection to the remote application. If the Socket parameter is non-blocking, TCPAccept will return a new Socket if an incoming connection request is already queued on the listening socket; otherwise, it will return the error status –10035, which means that the call would block.

TCPAccept returns a long integer, which is either a new socket for the accepted connection, or an error code less than zero. The new socket has the same blocking mode as the listening socket. The listening socket continues to listen for further incoming connection requests.

Example

; Accept incoming connections on port iPort
Calculate iPort as 6000
TCPSocket Returns iSocket
TCPBind (iSocket,iPort) Returns lStatus
TCPListen (iSocket) Returns lStatus
If lStatus=0
  Repeat
    TCPAccept (iSocket) Returns lConnectedSocket
  Until lConnectedSocket>=0
  ; client connected, get the whole message sent
End If
TCPClose (iSocket) Returns lStatus