socket.io.js not found on client

后端 未结 2 1167
情书的邮戳
情书的邮戳 2021-01-23 03:10

This question has been asked previously but haven\'t found any solution in prior replies.

Socket.IO gives me two problems:

  1. server side gave this error - ER
2条回答
  •  情话喂你
    2021-01-23 03:14

    The problem here is that you're telling Socket.IO to listen on a server that does not yet exist, causing an EACCES and therefore not serving the client file. This is what you're doing:

    // the HTTP server doesn't exist yet
    var io = require('socket.io').listen(server);
    var server = http.createServer();
    

    And if you saw in your server-side error console, you get this:

    info: socket.io started
    warn: error raised: Error: listen EACCES
    

    To fix this, move your listen function to after the server is created:

    var server = http.createServer();
    var io = require('socket.io').listen(server);
    

    Once Socket.IO listens properly, it will automatically serve the client file to /socket.io/socket.io.js. You don't need to find it or serve it manually.

提交回复
热议问题