0

I have a websocket server based on Jetty v9.3.9 The server sends text messages to clients from different Threads. A single client can receive multiple simultaneous messages from 2 different threads. For example: Thread 1: "message A" Thread 2: "message B"

Sometimes, not all the times, but around 4-5% of the time, the client doesn't receive all the messages. It receive either message A or B. The client is based on the browser.

I tested in both Firefox and Chrome, and I looked in web console to see if the message is received and is not.

The code I'm using for sending the message is

getSession().getRemote().sendString(this.message);

from http://download.eclipse.org/jetty/9.3.9.v20160517/apidocs/org/eclipse/jetty/websocket/api/RemoteEndpoint.html#sendString-java.lang.String-org.eclipse.jetty.websocket.api.WriteCallback-

Is this the right way to do this? Should I use sendStringByFuture(String text) ? Am I missing something.

On the server I have around 800-1k connected clients, that sends and receives multiple messages from different threads.

NOTE: I used websockets with Jetty since version 8 and I can't remember having this problems until I updated to 9, however I can't go back.

Thank you

Doua Beri
  • 10,612
  • 18
  • 89
  • 138
  • 1
    Interesting, when you say "the server sends text messages to clients from different threads" are you meaning multiple threads are using a single Session/Endpoint to send messages? – Joakim Erdfelt Jul 01 '16 at 15:35
  • @JoakimErdfelt yes, I'm sharing the Session object between threads and use session.getRemote().sendString(this.message); to send the message. Is this the right way to do it? – Doua Beri Jul 01 '16 at 16:55
  • I think my problem is related to this: https://blogs.oracle.com/PavelBucek/entry/is_websocket_session_really_thread . Any ideas? – Doua Beri Jul 01 '16 at 17:04
  • For whole message (not partial) send using the `RemoteEndpoint.Basic`, each `send()` blocks the calling thread and enters an outgoing message -> extensions -> frame queue. You should be able to do that scenario easily. – Joakim Erdfelt Jul 01 '16 at 17:19
  • @JoakimErdfelt Thanks for you answer. This might sound stupid, but how do I use RemoteEndpoint.Basic ? the method session.getRemote() returns an object that implements org.eclipse.jetty.websocket.api.RemoteEndpoint . Am I missing something? – Doua Beri Jul 01 '16 at 17:31
  • Are you using the Jetty WebSocket API or the JSR356 API? (your statements are confusing, and you seem to use the two interchangeably) – Joakim Erdfelt Jul 01 '16 at 18:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116228/discussion-between-doua-beri-and-joakim-erdfelt). – Doua Beri Jul 01 '16 at 18:49

0 Answers0