TCPSocket

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

Syntax

TCPSocket () Returns 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.

TCPSocket creates a new socket. The only use of such a socket is to bind a port to it using TCPBind, start listening on the port using TCPListen, and then accept incoming connections using TCPAccept.

Socket is an Omnis Long Integer field which receives the number of the allocated socket. If an error occurs, the command returns a negative number.

Example

; Create a new socket, bind it to port 6000 and listen for an incoming
; client connection
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
End If
TCPClose (iSocket) Returns lStatus