TypeError: io.connect is not a function

主宰稳场 提交于 2019-12-05 21:03:28

Note: socket = io.connect("http://localhost", {port: 8000, transports: ["websocket"]}); this has to be included in the client side javascript file where you load socket.io.js via script tag.

Change to this:

var util = require("util"),
    io = require("socket.io")({
      transports  : [ 'websocket' ]
    }),
    Player = require("./Player").Player,
    socket,
    players;

function init(){
    players = [];

    socket = io.listen(8000);

    setEventHandlers();

};
init();

Note Below is not supported by socket.io v1.0 you have to install v0.9 if you want to do it that way, use: $ npm install socket.io@0.9 -S

socket.configure(function() {
    socket.set("transports", ["websocket"]);
    socket.set("log level", 2);
});

Looging socket.io v1.0 log-level option is removed. Thus for logging one has to start program using debug module.

  1. install debug: npm install debug -S
  2. then run the program: DEBUG=* node entry_file.js
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!