2
SparkJava web套接字不起作用。每当我尝试使用websocket测试器连接到它时,在'ws:// localhost:4567/echo'中,它会得到一个'undefined'错误,并且不会连接,也不会调用sout或printStackTrace中的任何一个。SparkJava websocket不工作
@WebSocket
public class EchoWebSocket {
private static final Queue<Session> sessions = new ConcurrentLinkedQueue<>();
@OnWebSocketConnect
public void connected(Session session) {
System.out.println("Client connected");
//sessions.add(session);
}
@OnWebSocketClose
public void closed(Session session, int statusCode, String reason) {
System.out.println("Client disconnected");
//sessions.remove(session);
}
@OnWebSocketMessage
public void message(Session session, String message) throws IOException {
System.out.println("Got: ");// + message); // Print message
//session.getRemote().sendString(message); // and send it back
}
@OnWebSocketError
public void throwError(Throwable error) {
error.printStackTrace();
}
}
我怎么称呼它
Spark.webSocket("/echo", new EchoWebSocket());
Spark.init();
我不能重现这一点。你确定你在使用你在这里提供的代码吗?它在我的机器上没有任何问题。 – Selim