我想建立一个java websocket服务器。我写了一个简单的服务器端点:Java websocket服务器给404
@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>
当我打WS://本地主机:8080/WebSocket的-1.0 /测试从Javascript,我收到了404回应。我正在使用tomcat 8来部署这个。我在这里错过了什么?
我仍然得到404上午我在web.xml中缺少任何东西? – coder
你确定你在8080端口吗? –
是的,它是端口8080 – coder