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