javascript - What is the correct way to send position updates via WebSockets? -


i need broadcast position updates in game-world running node.js. current idea use binaryjs. i'm not sure correct way use it, though. have thought in 3 options:

how i'm doing currently, using socket.io: programmatically store buffer of position-updates happened in given amount of time , send @ once:

settimeout(function(){     //called fixed amount of times per second (40)     //this variable hold accumulated position changes on last 25ms     //var accumulated_position_changes = [id0,x0,y0,z0, id1,x1,y1,z1...];     client.send(accumulated_position_changes); },25); 

but if binary.js chunking (does it?), should indiscriminately send position changes every time happen?

myclass.prototype.set_position = function(x,y,z){     // called thousands times second     this.x = x, this.y = y, this.z = z;     client.send([this.id, x, y, z]); }; 

or should somehow create object deriving node.js's stream , use it? maybe stream.write? or way else? right way deal problem?

binary.js seems write packet every time write pipe, in use cases.

why not write position changes buffer, , use underscore.js' throttling. call update() or whatever, writes whole buffer of changes @ once. can call function want, use throttled version runs @ maximum of every 50ms or so.

that delay incredibly fast web applications. sure considering rate @ clients can receive , ack info. honestly, wouldn't update clients until data has been sent , acked. otherwise, have way high of update rate some.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -