简体   繁体   English

Cordova s​​etInterval()的替代/最佳实践?

[英]Cordova alternative/best practice for setInterval()?

I am currently sending UDP packets to a remote server using javascript's setInterval() function to loop through the process every 100ms. 我目前正在使用javascript的setInterval()函数将UDP数据包发送到远程服务器,以每100毫秒循环一次该过程。

My issue is that this seems somewhat unreliable since it is running on the same thread as the UI. 我的问题是,由于它在与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. 例如,Android设备每分钟发送大约450条消息,而iPhone每分钟发送大约380条消息。 Neither one is getting even close to the expected 600-message per minute. 没有人能接近预期的每分钟600条消息。

Any guidance would be appreciated. 任何指导将不胜感激。

WebRtC使用udp http://www.html5rocks.com/zh-cn/tutorials/webrtc/datachannels/要解决Rauls建议的线程问题,您可以使用webworker http://www.w3schools.com/html/html5_webworkers.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM