Sample code for 30+ languages & platforms
PowerBuilder

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

//  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.
li_Success = loo_Socket.BindAndListen(5000,25)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    return
end if

//  After the listener is established, accept the next incoming connection into a new Socket.
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."


destroy loo_Socket
destroy loo_ConnectedSock