WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400

后端 未结 16 1459
攒了一身酷
攒了一身酷 2020-12-04 21:08

I am trying to integrate Socket.io with Angular and I\'m having difficulties making a connection from the client-side to the server. I\'ve looked through other related quest

16条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 21:40

    Judging from the messages you send via Socket.IO socket.emit('greet', { hello: 'Hey, Mr.Client!' });, it seems that you are using the hackathon-starter boilerplate. If so, the issue might be that express-status-monitor module is creating its own socket.io instance, as per: https://github.com/RafalWilinski/express-status-monitor#using-module-with-socketio-in-project

    You can either:

    1. Remove that module
    2. Pass in your socket.io instance and port as websocket when you create the expressStatusMonitor instance like below:

      const server = require('http').Server(app);
      const io = require('socket.io')(server);
      ...
      app.use(expressStatusMonitor({ websocket: io, port: app.get('port') })); 
      

提交回复
热议问题