Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set success 0

set socket [new_CkSocket]

set success [CkSocket_BindAndListen $socket 5000 25]
if {$success == 0} then {
    puts [CkSocket_lastErrorText $socket]
    delete_CkSocket $socket
    exit
}

#  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.
set connectedSock [new_CkSocket]

set success [CkSocket_AcceptNext $socket 20000 $connectedSock]
if {$success == 0} then {
    puts [CkSocket_lastErrorText $socket]
    delete_CkSocket $socket
    delete_CkSocket $connectedSock
    exit
}

puts "Accepted a connection from [CkSocket_remoteIpAddress $connectedSock]"

delete_CkSocket $socket
delete_CkSocket $connectedSock