Farid Farhat
Farid Farhat

Reputation: 2310

Chat application using XMPP Server

I am making a chat application using an XMPP server. The chat application works great but I have a problem: when chatting between 2 users, I cannot know if the message from the first user has reached the server or not.

So how to know if a message from a first user reached the server without having to be worried about the second user if he is online or offline.

Please HELP

I am sending the message like this:

final SecureConnection sc = (SecureConnection)Connector.open("ssl://...", Connector.READ_WRITE);
is = sc.openInputStream();
os = sc.openOutputStream();
this.reader = new XmlReader(is);
this.writer = new XmlWriter(os);

public boolean sendMessage(final String to, final String msg) {
this.writer.startTag("message"); 
this.writer.attribute("type", "chat"); 
this.writer.attribute("to", to); 
this.writer.startTag("body"); 
this.writer.text(msg); 
this.writer.endTag(); 
this.writer.endTag(); 
this.writer.flush();
}

Upvotes: 0

Views: 812

Answers (2)

MattJ
MattJ

Reputation: 7924

If you are connected to the server and you send a message, you can be reasonably confident the message reached the server. If the client is on an unreliable network sometimes TCP connections do silently break, and it is a while before this is detected and they are closed. Possible solutions to this (in order of complexity):

  • Ping the server at regular intervals using XEP-0199.
  • Implement XEP-0198. Ultimate reliability, but more tricky to implement and requires server support.

The other issue you seem to be worried about is user2 seeing the message. I don't know about your application, how it is configured or how you want it to work. However most XMPP servers will automatically store messages sent to a user while they are offline. They are then delivered to the user when they come online. See XEP-0160 for more information.

Finally, you can use message receipts to know when user2 has received/read the message. These are described in XEP-0184, and are possibly the only thing you really need to implement if all you care about is knowing that user2 received the message.

Upvotes: 3

Lucifer
Lucifer

Reputation: 29670

you need to implement ACK/NACK notification in your code.

Upvotes: -1

Related Questions