Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoImap
    Boolean iStillConnected
    String sTemp1

    Move False To iSuccess

    //  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.

    Get Create (RefClass(cComChilkatImap)) To hoImap
    If (Not(IsComObjectCreated(hoImap))) Begin
        Send CreateComObject of hoImap
    End

    Set ComSsl Of hoImap To True
    Set ComPort Of hoImap To 993

    Get ComConnect Of hoImap "imap.example.com" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Perform a low-level check of the socket connection state.
    Get ComCheckConnection Of hoImap To iStillConnected
    If (iStillConnected = True) Begin
        Showln "The socket is still connected."
    End
    Else Begin
        Showln "The socket is no longer connected."
    End

    Get ComDisconnect Of hoImap To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure