Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SparkJava websocket不工作_Java_Websocket_Spark Java - Fatal编程技术网

SparkJava websocket不工作

SparkJava websocket不工作,java,websocket,spark-java,Java,Websocket,Spark Java,SparkJava web套接字无法工作。每当我尝试使用websocket测试仪连接到它时,在“ws://localhost:4567/echo”上,它会收到一个错误“undefined”,并且从不连接,也不会调用任何sout或printStackTrace @WebSocket public class EchoWebSocket { private static final Queue<Session> sessions = new ConcurrentLinkedQueue&l

SparkJava web套接字无法工作。每当我尝试使用websocket测试仪连接到它时,在“ws://localhost:4567/echo”上,它会收到一个错误“undefined”,并且从不连接,也不会调用任何sout或printStackTrace

@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", EchoWebSocket.class);

我无法复制这个。您确定正在使用此处提供的代码吗?它在我的机器上没有任何问题。传递处理程序的实例也可以。这两种选择都是可以接受的。
Spark.webSocket("/echo", EchoWebSocket.class);