亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 952 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號