web前端|js教程
Node.js,聊天服务器
web前端-js教程
使用Nodejs是如此简单的实现了一个简单的聊天服务器
adb 源码修改,vscode中怎么中断运行,ubuntu串口输出,tomcat 服务点不了,乌龟爬虫灯,php商业源码,厦门seo推广运营商,asp培训网站,苹果cmsv10模板购买lzw
实现代码如下:
源码采集器,ubuntu语言咋设置,怎么看tomcat源码,爬虫系列pyquery,php面对对象,河北互联网seo推广如何进行lzw
var net = require( et); var chatServer = net.createServer(),clientList = []; chatServer.on("connection",function(client){ client.name = client.remoteAddress + ":" + client.remotePort; client.write("Hi! "+client.name+" \n"); clientList.push(client); client.on("data",function(data){ //数据发送给客户端 broadcast(data,client); // clientList[i].write(data); }); client.on("end",function(){ clientList.splice(clientList.indexOf(client),1); }); client.on("error",function(e){ console.log(e) });});chatServer.listen(9000) function broadcast(message,client){ var cleanup = []; for(var i=0;i<clientList.length;i++){ if(client != clientList[i]){if(clientList[i].writable){ clientList[i].write(client.name = "says:"+message);}else{ cleanup.push[clientList[i]]; clientList[i].destory();} } }}
使用过程就是:
简历源码,ubuntu怎么查看mac,爬行爬虫的视频,php strace,查seo情况lzw
启动js
node chat.js
连接方式:telnet
telnet 127.0.0.1 9000