Socket IO chat repeating user connected

2019-07-26 21:08发布

Using the basic chat example from the socket.io website, it initially worked for the past few days but now is completely malfunctioning. When console.logging to check if users are connected, I get a never ending 'user connected' status and am unable to post anything to the chat. here's the code:

var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var port = process.env.PORT || 3000;

app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});

io.on('connection', function(socket){
console.log('user connected');
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});

server.listen(port, function(){
console.log('listening on *:' + port);
});

标签: socket.io
1条回答
Ridiculous、
2楼-- · 2019-07-26 22:06

I answered my own question in that I was using a brand new version of socket.io that apparently has bugs, because an older version ended up working with the same code.

查看更多
登录 后发表回答