Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incoming message not waking phone when asleep. #81

Closed
chrisdew opened this issue Sep 14, 2016 · 3 comments
Closed

Incoming message not waking phone when asleep. #81

chrisdew opened this issue Sep 14, 2016 · 3 comments

Comments

@chrisdew
Copy link

chrisdew commented Sep 14, 2016

Two or three years ago I wrote an app which opened a TCP connection. When it was asleep, an incoming TCP packet, over GPRS, would wake the phone enough for a TCP response to be sent, with no wakelocks required.

I'm trying to do the same thing over websockets now, but the websocket connections are being dropped while the phone sleeps.

Why is this, and what can I do to get TCP-like behaviour when the phone is asleep?

@eku
Copy link

eku commented Sep 15, 2016

@chrisdew Websocket connection have a keep-alive mechanism (ping/pong), that does not run while phone sleeps. So the server drops the connection when not receiving an pong from the client for a while.

@TakahikoKawasaki
Copy link
Owner

@chrisdew Depending on server-side and/or client-side configuration, a TCP connection is automatically closed if no data is transmitted through the connection. To put it the other way around, if data is transmitted periodically before the automatic close is triggered, the connection is kept alive.

In the WebSocket layer, Ping/Pong mechanism can be used for the purpose. If either the server or the client sends Ping (or Pong) frames periodically, the WebSocket connection (which is a kind of TCP connection) is kept alive. nv-websocket-client library provides setPingInterval() method and setPongInterval() method to make the task easy.

However, the following two are different things in different layers.

  1. An application sends Ping/Pong frames periodically in the WebSocket layer.
  2. An underlying operating system keeps TCP connections while the phone is asleep.

So, even if an application sends Ping frames periodically, an underlying operating system may drop the connection while the phone is asleep.

How to prevent an underlying operating system from dropping TCP connections while the phone is asleep varies depending on operating systems. The behavior cannot be controlled in the WebSocket layer.

@TakahikoKawasaki
Copy link
Owner

This seems to be an operating system / platform issue. I don't think it can be controlled in the WebSocket layer.

Please reopen this issue if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants