PureBasic
PureBasic
Check the IMAP Socket Connection
See more IMAP Examples
Demonstrates the Chilkat Imap.CheckConnection method, which checks whether the underlying TCP socket is currently connected to the IMAP server. This performs a low-level socket-state check and does not send an IMAP command. This example connects and checks the socket.
Background:
CheckConnection sits between the cached IsConnected and a full protocol round trip: it inspects the actual socket without sending an IMAP command, so it can catch a locally-closed socket that the cached flag would miss. It still cannot detect every half-open connection, though — only a real command like Noop that expects a server reply proves the session is genuinely alive end to end.Chilkat PureBasic Downloads
IncludeFile "CkImap.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Imap.CheckConnection method, which checks whether the underlying TCP
; socket is currently connected to the IMAP server. This is a low-level socket-state check
; and does not send an IMAP command.
imap.i = CkImap::ckCreate()
If imap.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkImap::setCkSsl(imap, 1)
CkImap::setCkPort(imap, 993)
success = CkImap::ckConnect(imap,"imap.example.com")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Perform a low-level check of the socket connection state.
stillConnected.i = CkImap::ckCheckConnection(imap)
If stillConnected = 1
Debug "The socket is still connected."
Else
Debug "The socket is no longer connected."
EndIf
success = CkImap::ckDisconnect(imap)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
CkImap::ckDispose(imap)
ProcedureReturn
EndProcedure