Sample code for 30+ languages & platforms
Xbase++

Accept the Next Incoming Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.AcceptNext, which waits for and accepts the next incoming connection on a listening socket, delivering it as a new connected Socket.

Background. A maxWaitMs of 0 waits indefinitely; a positive value waits up to that many milliseconds. For a TLS listener, acceptance includes the server-side TLS handshake.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSocket
LOCAL oConnectedSock

nSuccess := 0

oSocket := CreateObject("Chilkat.Socket")

nSuccess := oSocket:BindAndListen(5000, 25)
IF (nSuccess == 0)
    ? oSocket:LastErrorText
    oSocket:destroy()
    RETURN
ENDIF

//  Wait for and accept the next incoming connection on the listening socket.  maxWaitMs = 0 waits
//  indefinitely; a positive value waits up to that many milliseconds.  For a TLS listener, acceptance
//  includes the server-side TLS handshake.
oConnectedSock := CreateObject("Chilkat.Socket")
nSuccess := oSocket:AcceptNext(20000, oConnectedSock)
IF (nSuccess == 0)
    ? oSocket:LastErrorText
    oSocket:destroy()
    oConnectedSock:destroy()
    RETURN
ENDIF

? "Accepted a connection from " + oConnectedSock:RemoteIpAddress

oSocket:destroy()
oConnectedSock:destroy()