Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

loSocket = createobject("CkSocket")

llSuccess = loSocket.BindAndListen(5000,25)
if (llSuccess = .F.) then
    ? loSocket.LastErrorText
    release loSocket
    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.
loConnectedSock = createobject("CkSocket")
llSuccess = loSocket.AcceptNext(20000,loConnectedSock)
if (llSuccess = .F.) then
    ? loSocket.LastErrorText
    release loSocket
    release loConnectedSock
    return
endif

? "Accepted a connection from " + loConnectedSock.RemoteIpAddress


release loSocket
release loConnectedSock