DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
Variant vConnectedSock
Handle hoConnectedSock
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatSocket)) To hoSocket
If (Not(IsComObjectCreated(hoSocket))) Begin
Send CreateComObject of hoSocket
End
Get ComBindAndListen Of hoSocket 5000 25 To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Get Create (RefClass(cComChilkatSocket)) To hoConnectedSock
If (Not(IsComObjectCreated(hoConnectedSock))) Begin
Send CreateComObject of hoConnectedSock
End
Get pvComObject of hoConnectedSock to vConnectedSock
Get ComAcceptNext Of hoSocket 20000 vConnectedSock To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComRemoteIpAddress Of hoConnectedSock To sTemp1
Showln "Accepted a connection from " sTemp1
End_Procedure