Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Socket
oleobject loo_ConnectedSock

li_Success = 0

loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
    destroy loo_Socket
    MessageBox("Error","Connecting to COM object failed")
    return
end if

li_Success = loo_Socket.BindAndListen(5000,25)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    return
end if

//  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.
loo_ConnectedSock = create oleobject
li_rc = loo_ConnectedSock.ConnectToNewObject("Chilkat.Socket")

li_Success = loo_Socket.AcceptNext(20000,loo_ConnectedSock)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    destroy loo_ConnectedSock
    return
end if

Write-Debug "Accepted a connection from " + loo_ConnectedSock.RemoteIpAddress


destroy loo_Socket
destroy loo_ConnectedSock