Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to respond to a Web Services request via WebSockets
    primarykey
    data
    text
    <p>I have a WebSockets connection between a server and a client. This allows me to send a command to a client, and he responds me with data. The server has web services too. I can then tell, "do this command on that client". So we have:</p> <p>Client1 ---webservices--> server ---websockets---> Client2</p> <p>The problem is, the method on the server which receives the data from Client2 is <strong>void</strong>.</p> <p>How can I send back the data to Client1 ?</p> <p><strong>WebServices:</strong></p> <pre><code>@Path("/ws") public class QOSResource { public QOSResource(){} @Produces(MediaType.TEXT_PLAIN) @Path("/ping/{macAddr}") @GET public String getPing(@PathParam("macAddr") String macAddr){ return"Mac adresse : "+macAddr; //WebSocketsCentralisation.getInstance().ping(macAddr); } } </code></pre> <p><strong>WebSockets</strong></p> <pre><code>@OnWebSocketMessage public **void** onText(Session session, String message) { if (session.isOpen()) { if(firstConnection){ firstConnection = false; this.macAddr = message; WebSocketsCentralisation.getInstance().join(this); } ObjectMapper mapper = new ObjectMapper(); Object o; try { o = mapper.readValue(message, Object.class); if(o instanceof PingResult){ **// TODO return result to ws** } } catch (JsonParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre> <p>Thanks in advance for your help</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload