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