如何使Android设备没有持有唤醒锁的TCP连接互联网? [英] How to make the Android device hold a TCP connection to Internet without wake lock?

查看:315
本文介绍了如何使Android设备没有持有唤醒锁的TCP连接互联网?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序连接到服务器,虽然在移动连接,但允许设备进入睡眠模式。我希望当IP packates到达时醒来。

I want my application to be connected to server though the mobile connection, yet allowing the device to go into sleep mode. I expect it to wake up when IP packates arrives.

如何才能做到这一点?如何接收来自互联网的中断不会耗尽电池?

How can this be done? How to receive "interrupts" from the Internet without draining battery?

推荐答案

在被封锁在从TCP读取数据流的设备可以进入深度睡眠,当TCP流量来自于它会短暂地唤醒器件,如一旦一个位的检查是在你开始wakelock,直到你收到整个传输然后松开。

When you are blocked on a read from a tcp stream the device can go into a deep sleep and when tcp traffic comes in it will briefly wakeup the device, as soon as a bit is read in you start a wakelock until you have received the whole transmission then release it.

下面是网络插座一个例子,我已经跑了这个应用程序超过12小时,不带电池影响的背景。 <一href="https://github.com/schwiz/android-websocket-example">https://github.com/schwiz/android-websocket-example

Here is an example with web sockets, I've ran this app for over 12 hours in the background with no battery impact. https://github.com/schwiz/android-websocket-example

客户端是在这里,阻塞读处于启动方法。 <一href="https://github.com/schwiz/android-websockets/blob/master/src/com/$c$cbutler/android_websockets/HybiParser.java">https://github.com/schwiz/android-websockets/blob/master/src/com/$c$cbutler/android_websockets/HybiParser.java

The client is here, the blocking read is in the start method. https://github.com/schwiz/android-websockets/blob/master/src/com/codebutler/android_websockets/HybiParser.java

这篇关于如何使Android设备没有持有唤醒锁的TCP连接互联网?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆