基本信息
源码名称:基于socket.io的web即时聊天
源码大小:6.50M
文件格式:.zip
开发语言:js
更新时间:2019-05-13
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

实现了基于socket.io的web即时聊天,真正的运用推方式获取实时消息。服务器是基于nodejs。

io.on('connection', function (socket) {
  socket.emit('news',{ hello: 'Session ' socket.id });
  var socketId = socket.id;
  connectionList[socketId] = {authentication:false};
  async.auto({
authentication: function (callback) {
socket.on('authentication', function (data) {
connectionList[socketId].authentication = true;
socket.emit('result' , '1');
callback();
});
},
nickname: ['authentication', function(callback,results) {
socket.on('set nickname', function (name) {
if(connectionList[socketId].authentication) console.log("验证通过");
else {
console.log("验证不通过");
socket.disconnect();
callback("ERROR");
return;
}
connectionList[socketId].name = name;
socket.emit('news' , { hello: 'hi, ' name '!' });
socket.join(name);
callback("OK");
});
}]
}, function(err, results) {
});  
    socket.on('message', function (msg) {
        console.log('Message Received: ', msg);
var nickname = connectionList[socketId].name;
socket.broadcast.emit('message', 'From ' nickname ': ' msg);
    });

socket.on('disconnect', function () {
var log = require("./log").logger("index");
log.info('a connection was disconnect:' socketId);
console.log('a connection was disconnect:' socketId);
});
});