JavaScript Websocket interval: performance problems on mobile devices?

In my current project I discovered a problem using websockets with socket.io and node.js on mobile devices. It seems that there is a problem for mobile deviced handling socket messages in an interval.

I reduced it to a minimal scenario:

The server (minimal express.js server) sends messages to the client in an specific interval:

setInterval(function(){
  socket.emit('interval');
}, 500);

The client just messures the time between the received messages and displays them:

socket.on('interval', function (data) {
  timeElement.html(new Date() - startTime);
  startTime = new Date();
});

On a desktop (using Chrome) the resulting time between the messages is pretty stable at 515 ms. So its like a 15ms delay but message interval is consistent.

On a mobile device (I'm using a Galaxy Nexus with Chrome) the time varies between 400 and 600 ms with some more extrem spikes in either way.

I want to use such an interval as a game turn indicator and this problem results in a lot of lagging and uneven player movement on mobile devices.

Answer:1

You have no promises about when a network packet will get to you. If you're not using a reliable protocol like TCP, you can't be sure if a packet will get to you. Sometimes packets get dropped.

As it happens, you are using TCP (which is the underlying network-level protocol for WebSockets). When a TCP packet is lost, the network must identify the loss, and then resend the packet, causing a delay. It's possible that the mobile device's physical network card simply is more prone to drop packets than the physical card on your desktop.

Network message intervals are a terrible mechanism for reliable timing.

Another -- or an additional -- possible explanation (if you suspect packet loss is unlikely) is that on such a low-power mobile device, the network driver simply isn't getting enough time on the CPU (or is not getting its CPU time quite soon enough), so there are driver-level delays in processing the queue of packets received on the physical network device.

Answer:2

With the following code, when shift clicking the label, why isn't the checkbox's click handler fired in FF? Both Chrome and IE11 fires it. <script> function show(event) { alert((...

With the following code, when shift clicking the label, why isn't the checkbox's click handler fired in FF? Both Chrome and IE11 fires it. <script> function show(event) { alert((...

  1. checkbox in excel
  2. checkbox symbol
  3. checkbox in word
  4. checkbox in google docs
  5. checkbox emoji
  6. checkbox in google sheets
  7. checkbox icon
  8. checkbox css
  9. checkbox image
  10. checkbox text
  11. checkbox symbol in word
  12. checkbox in html
  13. checkbox checked
  14. checkbox unicode
  15. checkbox react
  16. checkbox value
  17. checkbox alt code
  18. checkbox bootstrap
  19. checkbox input
  20. checkbox onchange

So I'm trying to create a basic angular application that parses some CSV input, and fills a table with the parsed data. You can see a plunker of what I'm trying to achieve here - http://plnkr.co/...

So I'm trying to create a basic angular application that parses some CSV input, and fills a table with the parsed data. You can see a plunker of what I'm trying to achieve here - http://plnkr.co/...

  1. javascript parser angularjs
  2. defer parsing of javascript angularjs

Requirement : Trigger a jsp page refresh when some value in the server changes. Ajax is an option, but refreshing the JSP at a particular interval will increase the load on the server. Since i am ...

Requirement : Trigger a jsp page refresh when some value in the server changes. Ajax is an option, but refreshing the JSP at a particular interval will increase the load on the server. Since i am ...

  1. trigger page refresh javascript
  2. trigger page refresh react
  3. trigger page refresh angular
  4. trigger page refresh jquery
  5. trigger page refresh
  6. trigger page refresh c#
  7. trigger page refresh asp.net
  8. trigger page refresh java
  9. js trigger page refresh
  10. php trigger page refresh
  11. ajax trigger page refresh
  12. vue trigger page refresh
  13. html trigger page refresh
  14. jsf trigger page refresh
  15. browser trigger page refresh
  16. salesforce trigger refresh page
  17. angular 6 trigger page refresh
  18. onbeforeunload trigger on page refresh

I'm building a JQM app. It's a multiple page app that uses the jquery mobile page divs to hide and show pages as it goes through. The pages are laid out like: <div data-role="page" id="listpets" ...

I'm building a JQM app. It's a multiple page app that uses the jquery mobile page divs to hide and show pages as it goes through. The pages are laid out like: <div data-role="page" id="listpets" ...

  1. pagecontainer show
  2. jquery mobile pagecontainer show