Menu

Correctly closing an IM/ICQ connection

2009-01-01
2012-09-15
  • E. Getchell

    E. Getchell - 2009-01-01

    Hello,

    I'm in the process of implementing a simple IM notification routine using JOscarLib in a Tomcat application server.

    Since there are only around 5 notifications a day and resources are scarce on the server, I’m trying to only open a connection to send a single message and then shut down the connection after the message has successfully been sent. Using the SampleSendMessage code supplied, I added the following modification:

    public void update(Observable obs, Object obj)
    {
    OscarInterface.sendBasicMessage(con, receiver, "Dude, I'm online !");
    try
    {
    con.close();
    }
    catch (IOException ioE)
    {
    ioE.printStackTrace();
    }

    }

    What seems to be happening is that the sendBasicMessage call is non-blocking, so that con.close() call is closing the connection before the sendBasicMessage call finishes, so the message is not sent.

    What is the correct way to determine when a message has been sent so that the connection can be closed?

    Thanks!

    Eric

    Great library by the way!

     
    • Lolo101

      Lolo101 - 2009-01-02

      Hi Eric and thanks for using the lib !

      I'm sorry but i have to contradict you. The call to OscarInterface.sendBasicMessage eventually calls outputStream.write / outputStream.flush
      Hence the call is blocking and OscarInterface.sendBasicMessage should ensure your message is sent to the server.
      You say the message is not sent. How do you know ? I guess you know the peer didn't received the message. But did you try to monitor the data sent through the TCP connection with Wireshark for instance ?
      Maybe you should wait for message ack before closing the connection, in order to make sure your message is delivered to the peer, or implement a retry mechanism ?

      Hope this helps, let me know !

      Loïc

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.