0

I'm developing an online game fully in javascript(both server and client). Due to the fact that people can make custom maps/servers in my game, one of the options for the base server script to upload the map file to the client upon connection is through websockets, but I haven't found anywhere how to limit websockets speed so the server won't lag every time a new person connects and download its map.

One way to getting around this that I had thought was splitting the buffer where the map file is saved(I read it using fs.readFileSync then I make a buffer where it stays until requested) into many small buffers, then upload only one of them per second to the client, thus creating a "fake" upload speed limit for the server, theoretically avoiding lags and/or crashes.

My question is: is that a good idea? Would that work as intended?

peq42
  • 346
  • 4
  • 18
  • You plan to solve a theoretical lag by introducing a real lag into your code? – BlueWater86 Jan 13 '20 at 04:08
  • The words above are a comment not an answer; the words were intended to get you thinking. You still have the same amount of bandwidth consumed regardless of how you throttle. If you want a solid architecture that can scale appropriately look at scaling out through a messaging service; not hand cutting your own throttling protocol. – BlueWater86 Jan 13 '20 at 05:47
  • You can [stream via websockets](https://stackoverflow.com/questions/48627210/how-to-stream-data-over-socket-io-to-client) – Jonas Wilms Jan 13 '20 at 06:13

0 Answers0