2

I am currently sending UDP packets to a remote server using javascript's setInterval() function to loop through the process every 100ms.

My issue is that this seems somewhat unreliable since it is running on the same thread as the UI. Is there a more reliable way I should be doing this?

var myVar = setInterval(function() {
            sendUDP(msg);
        }, 100);

From my current tests this method doesn't seem to be consistent. For example, an Android device was sending around 450-messages a minute, and an iPhone was sending around 380-messages a minute. Neither one is getting even close to the expected 600-message per minute.

Any guidance would be appreciated.

TheJason
  • 494
  • 6
  • 18
  • Have you debug using timeline to see if sendUDP function is blocking the main thread? if so, you can use Webworkers, and communicate to the work on that setInterval. – Raul Fernandez Apr 13 '16 at 14:55

1 Answers1

0

WebRtC use udp http://www.html5rocks.com/en/tutorials/webrtc/datachannels/ For solve thread problem as suggested from Rauls you can use webworker http://www.w3schools.com/html/html5_webworkers.asp

Flatlineato
  • 1,066
  • 15
  • 32