Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6391107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:37:53+00:00 2026-05-25T03:37:53+00:00

I’m trying to make a simple multiplayer game using canvas, socket.io and node.js. Everything’s

  • 0

I’m trying to make a simple multiplayer game using canvas, socket.io and node.js.
Everything’s OK until another person connects (I open another tab and load the game there). When that happens, everything slows down and eventually stops (I can’ move around).

How it works:
When someone connects to the server, the server saves his socket in an array object and starts communication with the client. The client sends an object containing it’s name and position and then the server goes trough that array of sockets and sends that to everyone else who is connected. When a client receives a message, it extracts the data, does something with it (like drawing based on the position) and then sets a timeout in 10ms to reply to the server with his position and name. This goes on and on and works well until I open a new window/tab and reconnect, as I said.

Why does it slow down when I start another client? Here’s the code:

server.js (this is just a piece of code, the rest is from the socket.io example)

io.sockets.on('connection', function (socket) {
     socket.emit('init', {id: names[players.length], level: 5});
     socket.on('got', function (data) { 
          console.log("got");
          players.push(new Player(socket));
          socket.emit('update', {msg: "ks"});
     });

     socket.on('update', function (data){
          for (i = 0; i < players.length; i++)
          {
               players[i].socket.emit('update', {msg: data});
          }
     });
});

Player = function(socket)
{
     this.socket = socket
}

game.js

self.socket.on('init', function (data) {
      self.pl = new self.Player(data.id, data.level);
      console.log(self.pl.id);
      self.defined = true;
      self.socket.emit('got', { my: "data" });
 });

 self.socket.on('update', function (data){
      self.pars(data);
          setTimeout(function(){self.socket.emit('update', {'pos': self.pl.pos, 'id': self.pl.id})}, 10);        
 });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:37:54+00:00Added an answer on May 25, 2026 at 3:37 am

    My first thought is resource issues, I’m guessing this is all running on your local machine, you might just be eating up all the resources.

    It could be anything from cpu to connections. Hard to say without more info.

    Is your code leaving connection to the clients open the entire time time?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.