© Jorge Acetozi 2017

Jorge Acetozi, Pro Java Clustering and Scalability, https://doi.org/10.1007/978-1-4842-2985-9_20

20. Sending a User’s Private Messages over WebSocket

Jorge Acetozi

(1)São Paulo / SP, Brazil

Sending private messages can be a little bit trickier than sending public ones. Let’s take a look at the JavaScript code, shown here:

function sendMessage() {  var instantMessage;  if (spanSendTo.text() == "public") {    instantMessage = {      'text' : inputMessage.val()    }  } else {    instantMessage = {      'text' : inputMessage.val(),      'toUser' : spanSendTo.text()    }  }  stompClient.send("/chatroom/send.message", {}, JSON.stringify(instantMessage));  inputMessage.val("").focus();}

When the client sends a private message in the ...

Get Pro Java Clustering and Scalability: Building Real-Time Apps with Spring, Cassandra, Redis, WebSocket and RabbitMQ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.