Reputation: 107
i`m new in node js.
I make chat for browser game using node js and socket.io. After some days of learning and coding chat works fine, but i get on problem - client browsers hangs after more client actions.
For example: client click "add" button to add text to the chat many times, and after every time he click it, browser hangs more and more, but after page refresh, all works great, till he click again "add" button many times.
And this problem appears not only on "add" button, but when client change chat (show only private or public chat) many times too.
I don`t think that problem is in server code, because, when browser hangs for me, for other clients chat works fine. So i think problem is on client side. There I use socket.io with default settings.
Maybe someone get same problem and know how to fix it?
<script src="sockets/socket.io.min.js"></script>
<script>
var socket = io.connect('http://'+chatSocketAddress+':'+chatSocketPort);
function ANgetChatRecords(){
socket.emit('getRecords', { my_id:my_id, type:chat_pub_chatShow, my_perm:my_perm, lang:my_lang });
socket.on('getRecordsAnswer', function (data) {
document.getElementById("chatbox_pub_entry").innerHTML = data.text;
});
} //and ther other similar functions, like add record, delete record ...
</script>
Upvotes: 1
Views: 2582
Reputation: 1126
I was just saying that you could be setting more socket.on() even if not explicitly. The code you have there seems clean but maybe you're adding more to the same event and stacking them. Add some console logs so you can see how many times they are actually called.
my code looks like this:
listenForMessage: function(){
param_socket.on("new", function (data) {
console.log('new');
console.log(data);
app.newHandler(data);
});
param_socket.on("done", function (data) {
console.log('done');
app.doneHandler(data.id,data.success)
});
param_socket.on("change", function (data) {
console.log('change');
app.changeHandler(data.id,data.success)
});
},
One more thing, are you calling this function only once? Because you are setting up the event.
Upvotes: 1