javascript - How can I control the rate of http requests in a JS script running on an online web game? -


i trying build learning bot online internet game. part of code have following function:

    oeftimer: function() {         var start = date.now();         /*          bot logic         */         settimeout(userinterface.oeftimer, (1000 / bot.opt.targetfps) - (date.now() - start));     }, 

it's function didn't wrote. part of logic depends on ability send http requests , responds them (this done using $.ajax jquery).

now, problem oeftimer fast , sends lot of http requests, wanted increase time between each call function using settimeout (so less requests sent). when did this, when game ended, of requests have never been sent , got following error in console:

websocket in closing or closed state. 

since in original code time between each call oeftimer considered fps of game, guesses there connection.

how can solve problem? aim control rate of amount of requests sent per time unit.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -