0

I'm working on web chat where user log in and can send message to any other logged in user. This is realized using long polling on client side and async java servlet on server side. It works well, until I log in under the same name from two different devices. Once the servlet receives the message for user A, it searches for the first waiting request of A (first because the second one may be waiting for another message), sends him the message and deletes it from internal queue. However, when they are two logged in A clients (mobile and PC for example) only the first one receives the message. I can't send it for all A requests, because the second waiting A request may be another from one device and sending the message twice is not good. Do you have any ideas how to solve this on the server side? How to send message to all devices of user A, but not more times to more waiting request from one device of user A.

Thanks

xwinus
  • 886
  • 3
  • 12
  • 28

1 Answers1

1

Use a message queue technology such as ZeroMQ or RabbitMQ to ensure unique delivery of messages, fanouts, etc. Do not reinvent this particular wheel.

Also JMS - I've never used it since I've needed language-independence in these situations but perhaps it's simpler if you're willing to assume Java-to-Java.

djechlin
  • 59,258
  • 35
  • 162
  • 290
  • well, unfortunately I'm not able to install anything to the server. All I can to do is to use some Java libraries and/or modify Glassfish server – xwinus Mar 12 '13 at 20:19
  • @VaclavSvejcar Run MQ server on separate server for instance. Zero MQ you may be able to do entirely in process. The point is your question is pretty much not constructive - you're asking us to design a robust reliable message protocol, and you could begin by researching these technologies and either learn from their API and design or use them out of the box. – djechlin Mar 12 '13 at 20:26