eclipse - How to Enable mouse control of Jetty Server (Java Robot function)? -
i made websocket in java jetty , eclipse, following guide http://jansipke.nl/websocket-tutorial-with-java-server-jetty-and-javascript-client/ client sends message "touch" server, server , displays on console through onmessage () method. if in onmessage () method insert mouse control, server shuts down no reason. there function prevents mouse control? how can solve problem?
using eclipse, windows 10, jetty 9. created web application javaee , loaded librerire jetty properties-> java build path-> libraries-> addjars ...
client javascript
<script> var ws = new websocket("ws://192.168.1.5:8080/"); ws.onclose = function() { alert("software chiuso!"); }; ws.onerror = function(err) { alert("errore nella comunicazione con il software. controlla la rete,attiva il software e riprova aggiornando la pagina!!!"); }; addeventlistener("click", function() { var el = document.documentelement , rfs = el.requestfullscreen || el.webkitrequestfullscreen || el.mozrequestfullscreen ; rfs.call(el); }); function touchhandler(event) { //if (!event.changedtouches || !event.changedtouches[0]) if (event.type == "touchstart") ws.send("touch"); if (event.type == "touchcancel") ws.send("touchcancel"); if (event.type == "touchend") ws.send("touchend"); if (event.type == "touchmove") ws.send("touchmove"); }; document.addeventlistener("domcontentloaded", function() { document.addeventlistener("touchstart", touchhandler, true); document.addeventlistener("touchmove", touchhandler, true); document.addeventlistener("touchend", touchhandler, true); document.addeventlistener("touchcancel", touchhandler, true); }, false); </script>
server main
public class websockettest { public static void main(string[] args) throws exception { server server = new server(8080); websockethandler wshandler = new websockethandler() { @override public void configure(websocketservletfactory factory) { factory.register(mywebsockethandler.class); } }; server.sethandler(wshandler); server.start(); server.join(); }
onmessage method
@websocket public class mywebsockethandler { static session session; @onwebsocketclose public void onclose(int statuscode, string reason) { //system.out.println("close: statuscode=" + statuscode + ", reason=" + reason); } @onwebsocketerror public void onerror(throwable t) { system.out.println("error: " + t.getmessage()); } @onwebsocketconnect public void onconnect(session session) throws ioexception { system.out.println("connect: " + session.getremoteaddress().getaddress()); } @onwebsocketmessage public void onmessage(string message) throws awtexception, ioexception { //system.out.println(message); if( message.equals("touch")) new robot().mousepress(inputevent.button1_mask); if( message.equals("touchmove")) new robot().mousepress(inputevent.button1_mask); if( message.equals("touchend")) new robot().mouserelease(inputevent.button1_mask); }
the server never ends if use system.out.println (message), when use robot function control mouse click, first touch ends server , closes. can me? much
Comments
Post a Comment