node.js - Why does my multiplayer javascript game slow down when another client (new tab) connects? -
I am trying to use a simple multiplayer game canvas, socket.o and node.js. Everything is fine unless someone else connects (I open another tab and load the game there). When this happens, everything gets slowed down and finally closes (I can 'move around').
How it works: When one connects to a server, the server saves its socket in an array object and the customer. The customer sends an object containing the name and location of that item, and then the server is sent to the array of chairs and that the rest connects. When a customer receives the message, he removes the data, does something with it (as the drawing on the basis of the situation) and then sets one timeout at 10.2 so that the server answers with its status and name . As long as I open a new window / tab and reconnect it, it works fine and works. as I said.
Why do I slow down when I start another client? Here is the code:
server.js (this is just a piece of code, the rest is from socket.io example)
io.sockets.on ('connection' , Function (socket) {socket.emit ('init', {id: name [player.lumbies], level: 5}); socket.on ('found', function (data) {console.log ("Socket. Imit ('update', {msg: "ks"})}}; socket.on ('update', function (data) {for (for) i = 0; i game.js
self-sock .on ('init', function (data) {self.pl = new self player (d) T.ID, Data.Level); console.log (self.pl.id); self.defined = true; self.socket.emit ('found', {my: "info"});}); Self. Socket.on ('update', function) {sepalers}; set timeout (function () {self.socket.emit ('update', {'pos': self.pl.pos, 'id': Self.pl.id})}, 10);});
My first The idea is resource problem, I'm guessing that it's running on all of your local machines, you can just eat all the resources.
This can be anything for connection to the CPU. Difficult to say without much information.
Is your code open to the time the client leaves the connection?
Comments
Post a Comment