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:
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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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!
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