我正在尝试构建一个Java WebSocket服务器。我已经编写了一个简单的服务器端点:
@ServerEndpoint(value = "/test")
public class EndPoint {
static Queue<Session> queue = new ConcurrentLinkedQueue<Session>();
public static void send(int a, int b) {
try {
for(Session session : queue) {
session.getBasicRemote().sendText("a = " + a + ",b=" + b);
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
@OnOpen
public void openConnection(Session session) {
queue.add(session);
}
@OnClose
public void closeConnection(Session session) {
queue.remove(session);
}
@OnError
public void error(Session session, Throwable t) {
queue.remove(session);
}
}
我的web.xml文件看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
</web-app>
当我从Javascript访问ws://localhost:8080/websocket-1.0/test时,会收到404错误响应。我使用的是Tomcat 8进行部署。我错过了什么?