Sample code for 30+ languages & platforms
Visual FoxPro

Bind and Listen for Incoming Connections

See more Socket/SSL/TLS Examples

Demonstrates Socket.BindAndListen, which binds a TCP listener to a port and places it into listening mode, then accepts an incoming connection.

Background. The backlog argument bounds the queue of pending connections. When ClientIpAddress is empty, the listener binds to all interfaces. After listening, call AcceptNext to accept connections.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSocket
LOCAL loConnectedSock

lnSuccess = 0

loSocket = CreateObject('Chilkat.Socket')

*  Bind a TCP listener to a port and place it into listening mode.  The 2nd argument is the backlog,
*  the maximum number of pending connections allowed to queue.
lnSuccess = loSocket.BindAndListen(5000,25)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    CANCEL
ENDIF

*  After the listener is established, accept the next incoming connection into a new Socket.
loConnectedSock = CreateObject('Chilkat.Socket')
lnSuccess = loSocket.AcceptNext(20000,loConnectedSock)
IF (lnSuccess = 0) THEN
    ? loSocket.LastErrorText
    RELEASE loSocket
    RELEASE loConnectedSock
    CANCEL
ENDIF

? "Accepted a connection."

RELEASE loSocket
RELEASE loConnectedSock