socket.io有个报错,不过链接可以正常使用
服务端:
io.on('connection', function(socket){
console.log('c')
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data)
})
socket.on('disconnect', function () {
io.sockets.emit('user disconnected');
});
socket.on('mes', function(e){
io.emit('aaa','hahahahahah')
})
})
http.listen(9999, function(){
console.log('socket on *:9999')
});客户端:
this is my page.

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
服务端那里有点问题吧,
socket.on('disconnect', function () { // 这个时候用户的socket连接已经断掉了, 你还往客户端发送消息, 这样做适合吗? io.sockets.emit('user disconnected'); });