Socket.io - failed: Connection closed before receiving a handshake response

前端 未结 5 1364
庸人自扰
庸人自扰 2021-01-01 15:24

Socket.io for NodeJS doesn\'t seem to work as a websocket server

For some reason, socket.io ALWAYS fallback to the long polling and if I force the w

5条回答
  •  一整个雨季
    2021-01-01 16:15

    Slightly related to what @Lucas Klaassen answered: I had the following:

    let express = require('express');
    let app = express();
    let http = require('http').Server(app);
    let io = require('socket.io')(http);
    // this is the culprit:
    app.listen(port);
    

    Changing last line is what fixed it:

    http.listen(port);
    

提交回复
热议问题