Infinite LOOP: NodeJS "message" event looping
Hello everybody, I'm testing 0.7 socket.io version.
This the nodejs code:
var io = require('socket.io'),
http = require('http');
var app = http.createServer(),
io = io.listen(app);
app.listen(8057);
io.sockets.on('connection', function(socket) {
console.log("New connection");
socket.on('message', function (message) {
console.log("Received: " + message);
socket.send('Text from server');
});
});
This is the client code:
<script src="http://127.0.0.1:8057/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://127.0.0.1:8057');
socket.on('connect', function() {
console.log("connected");
socket.send("Text from client");
});
socket.on('disconnect', function() {
console.log("disconnected");
});
socket.on('message', function(message) {
console.log(message);
});
</script>
I have no problem with the connection, I see "connected" on the client's console.
As you see there is only one message that the client send to the server after connected. The problem is that the "message" event on NodeJS is looping, on the nodejs console i see:
Received: Text from server
debug - websocket writing 3:::Text from server
debug - websocket received data packet 5:::{"name":"message","args":["Text from server"]}
debug - got packet
Received: Text from server
debug - websocket writing 3:::Text from server
debug - websocket received data packet 5:::{"name":"message","args":["Text from server"]}
debug - got packet
Received: Text from server
debug - websocket writing 3:::Text from server
debug - websocket received data packet 5:::{"name":"message","args":["Text from server"]}
debug - got packet
Received: Text from server
debug - websocket writing 3:::Text from server
debug - websocket received data packet 5:::{"name":"message","args":["Text from server"]}
debug - got packet
Received: Text from server
debug - websocket writing 3:::Text from server
debug - websocket received data packet 5:::{"name":"message","args":["Text from server"]}
debug - got packet
Received: Text from server
debug - websocket writing 3:::Text from server
debug - websocket received data packet 5:::{"name":"message","args":["Text from server"]}
debug - got packet
Received: Text from server
debug - websocket writing 3:::Text from server
debug - websocket received data packet 5:::{"name":"message","args":["Text from server"]}
debug - got packet
Received: Text from server
debug - websocket writing 3:::Text from server
debug - websocket received data packet 5:::{"name":"message","args":["Text from server"]}
debug - got packet
too many times....I have to block the server with CTRL-C to stop those messages.
It seems socket.send('Text from server') send the message to itself. There are not replies from the client, only one at the beginning.
Is it a bug?
Bye.
@dall did you close the issue because you found the solution ? I'm seeing the same thing ; let me know if you found the reason, otherwise I'll see if I can work on a fix.
Yes, it has been fixed with the 0.7.2, now i don't have that problem...
did you try 0.7.2?
On 28/06/2011 12:41, paisible wrote:
@dall did you close the issue because you found the solution ? I'm seeing the same thing ; let me know if you found the reason, otherwise I'll see if I can work on a fix.
@dall actually I'm not seeing exactly the same thing. Just experiencing an "echo" type of behaviour when a connection stays open, which leads to messages being pinged back and forth for what seems to be an increasingly longer period of time. Still would like to know if you resolved this problem, thanks.
what browser + socket.io version are you using? code?
On 28/06/2011 12:44, paisible wrote:
@dall actually I'm not seeing exactly the same thing. Just experiencing an "echo" type of behaviour when a connection stays open, which leads to messages being pinged back and forth for what seems to be an increasingly longer period of time. Still would like to know if you resolved this problem, thanks.
I'm using socket.io v.0.7.2 with Chrome (on mac).
I think in my case it might be linked to issue https://github.com/LearnBoost/Socket.IO-node/issues/280. Will confirm as soon as I investigate a bit more.