|Re: [jetty-users] WebSockets: Specific Client Message|
Oh...how stupid of me! So it was correct what i did. thank you for your help.And a servlet is the correct way to use websockets in jetty? or is there another way?
best regards hschenk Simone Bordet schrieb:
Hi, On Tue, Jan 10, 2012 at 19:37, Hendrik Schenk <hschenk@xxxxxxx> wrote:Ok, so far. That is what i use already ;) But i get a problem with this example, if i use multiple clients respectively parallel requests/connections . If two or more clients connect to the server and the server answers, each client get all answers. For example: Client 1 sends "hello" Client 2 sends "world" (at the same time) Client 1 gets hello world or world hello Client 2 gets the same. I solved the problem by avoiding "private final Set<ChatWebSocket> _members = new CopyOnWriteArraySet<ChatWebSocket>();" in my Servlet-Class and in my Server-Class. Where is that good for?!?! I do not understand it.It's a single room chat: if a client sends a message, all other clients must receive it. That's why the example is iterating over the _members in onMessage(). If you want to reply (and not broadcast), just use the Connection object to reply to the client that sent the message. Simon
Back to the top