Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set success 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.

set imap [new_CkImap]

CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993

set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

#  Perform a low-level check of the socket connection state.
set stillConnected [CkImap_CheckConnection $imap]
if {$stillConnected == 1} then {
    puts "The socket is still connected."
} else {
    puts "The socket is no longer connected."
}

set success [CkImap_Disconnect $imap]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}


delete_CkImap $imap