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:
Client1 ---webservices--> server ---websockets---> Client2
The problem is, the method on the server which receives the data from Client2 is void.
How can I send back the data to Client1 ?
WebServices:
@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);
}
}
WebSockets
@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();
}
}
}
Thanks in advance for your help