Websocket server using Netbeans and Tomcat 8

I'm having trouble accessing a websocket server using Netbeans and Tomcat 8.0.9 (Error during WebSocket handshake: Unexpected response code: 404). Here is my java code:

package WebSocketServer; import java.util.Collections; import java.util.HashSet; import java.util.Set; import javax.websocket.Session; @javax.websocket.server.ServerEndpoint("/endpoint") public class WebSocketServer { private static Set<Session> peers = Collections.synchronizedSet(new HashSet<Session>()); @javax.websocket.OnMessage public String onMessage(String message) { return null; } @javax.websocket.OnOpen public void onOpen (Session peer) { peers.add(peer); } @javax.websocket.OnClose public void onClose (Session peer) { peers.remove(peer); } }

javascript:

var wsUri = "ws://" + document.location.host + "/WebSocketServer/endpoint"; var websocket = new WebSocket(wsUri); websocket.onerror = function(evt) { onError(evt) }; function onError(evt) { console.log(evt); writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); } // For testing purposes var output = document.getElementById("output"); websocket.onopen = function(evt) { onOpen(evt) }; function writeToScreen(message) { output.innerHTML += message + "<br>"; } function onOpen() { writeToScreen("Connected to " + wsUri); } // End test functions

I am using Java EE7 and read there were some issues with Tomcat 7 but that these have been resolved with Tomcat 8?

Category:java Views:20 Time:2019-03-17

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.142 (s). 11 q(s)