WebSocket握手错误:意外的响应代码:400

时间:2019-05-16 08:04:42

标签: java websocket socket.io handshake engine.io

我必须在项目中使用engine.io-server-java。当我启动 eio 函数时,请求失败并引发了400个错误请求。如何调试此问题?是否有适用于engine.io-server-java的文档?

错误

  

与'ws:// localhost:8080 / engine.io /?EIO = 3&transport = websocket&sid = Mg_ZSd5'的WebSocket连接失败:WebSocket握手期间出错:意外的响应代码:400

请求标头

代码:

@WebServlet("/engine.io/*")
public class SocketIO extends HttpServlet {
    private final EngineIoServer server = new EngineIoServer();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
        server.handleRequest(request, response);
        server.on("connection", new Emitter.Listener() {
            @Override
            public void call(Object... arg0) {
                System.out.println("Socket connected");         
            }
        });
    }
}

客户代码:

var io = eio("http://localhost:8080", {transport: ["websocket"], upgrade: true, reconnection: false});

0 个答案:

没有答案