java - Unable to connect via websocket connection -
i'm trying create simple websocket connection in project.
java code:
@serverendpoint("/echo") public class echoendpoint { @onmessage public void onmessage(session session,string message){ try{ system.out.println(message); } catch(exception e){ system.out.println(e.getmessage()); } } }
html , javascript code:
<button type="button" onclick="websockettest()">send</button> <script type="text/javascript"> function websockettest() { alert("websocket supported browser!"); // let open web socket var ws = new websocket("ws://localhost:8080/echo"); ws.onopen = function() { // web socket connected, send data using send() ws.send("message send"); alert("message sent..."); }; ws.onmessage = function (evt) { var received_msg = evt.data; alert("message received..."); }; ws.onclose = function() { // websocket closed. alert("connection closed..."); }; } </script>
after pressing button got errorwebsocket connection 'ws://localhost:8080/echo' failed: error during websocket handshake: unexpected response code: 404
jboss wildfly8 used application server.
any idea? or working example?
this because put wrong path here:
var ws = new websocket("ws://localhost:8080/echo");
if application packed eg: websocketapp.war (or if set context-path on websocketapp) should use:
var ws = new websocket("ws://localhost:8080/websocketapp/echo");
Comments
Post a Comment