为了账号安全,请及时绑定邮箱和手机立即绑定

client 无法监听connect事件?

client 无法监听connect事件?

Helenr 2018-08-20 15:14:40
var events = require('events');var net = require('net');var channel = new events.EventEmitter();channel.clients = {};channel.subscriptions = {};channel.on('join',function(id,client){    console.log('connect');    this.clients[id] = client;    this.subscriptions[id] = function(senderId,message){        console.log(message);        if(id != senderId){            this.clients[id].write(message);        }    };    this.on('broadcast',this.subscriptions[id]);});var server =  net.createServer(function(client){    var id = client.remoteAddress+':'+client.remotePort;    client.on('connect',function(){        console.log('client connect');        channel.emit('join',id,client);    });    client.on('data',function(data){        data = data.toString();        console.log(data);        channel.emit('broadcast',id,data);    });});server.listen(8887);这句始终不被执行,为什么? client.on('connect',function(){ console.log('client connect'); channel.emit('join',id,client); });
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 928 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信