PureBasic
PureBasic
Wait for a Socket to Become Writable
See more Socket/SSL/TLS Examples
Demonstrates Socket.SelectForWriting, which waits for the socket, or sockets in a socket set, to become writable. It returns 1 if writable, 0 on timeout, or -1 on error.
Background. A timeoutMs of 0 performs a nonblocking poll. This is useful before attempting to send when the peer may be applying flow control.
Chilkat PureBasic Downloads
IncludeFile "CkSocket.pb"
Procedure ChilkatExample()
success.i = 0
socket.i = CkSocket::ckCreate()
If socket.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Connect to the server using TLS.
bTls.i = 1
maxWaitMs.i = 5000
success = CkSocket::ckConnect(socket,"example.com",5000,bTls,maxWaitMs)
If success = 0
Debug CkSocket::ckLastErrorText(socket)
CkSocket::ckDispose(socket)
ProcedureReturn
EndIf
; Wait up to 5 seconds for the socket (or sockets in a socket set) to become writable. Returns 1 if
; writable, 0 on timeout, or -1 on error.
ready.i = CkSocket::ckSelectForWriting(socket,5000)
If ready < 0
Debug CkSocket::ckLastErrorText(socket)
CkSocket::ckDispose(socket)
ProcedureReturn
EndIf
If ready <> 1
Debug "The socket did not become writable before the timeout."
CkSocket::ckDispose(socket)
ProcedureReturn
EndIf
Debug "The socket is ready for writing."
CkSocket::ckDispose(socket)
ProcedureReturn
EndProcedure