套接字连接需要android应用程序锁吗?

发布于 2025-01-04 16:29:34 字数 363 浏览 1 评论 0原文

我的应用程序通过我编码的服务与服务器保持套接字连接,但是一旦手机休眠(屏幕关闭后几分钟),我无法从休眠的手机获得典型的响应。当服务接收到网络事件时,通常会播放声音。

我的问题是,我是否需要唤醒锁才能使我的应用程序功能正常。如果是这样,这个wake_lock对哪些组件有帮助?我很好奇声音和插座连接。我可以仅使用部分唤醒锁来做到这一点吗?

至于socket连接,如果是在wifi下进行的话,是否需要额外加个wifi锁?套接字连接仅包含一次小事务,那么有没有一种方法可以让套接字连接不在wifi下(即使用户启用了wifi),这样我就不必锁定wifi并浪费电力?或者套接字连接是否只能在 3g/4g 下方便地完成,或者可以从 wifi 优雅地退化到 3g/4g?

谢谢!

my app maintains a socket connection with a server through a Service I coded, but once the phone sleeps (a couple minutes after the screen turns off), I am unable to get the typical response from the sleeping phone. A sound is normally played when the Service receives a network event.

My question is, do I need a wake_lock to be able to have my app function. If so, for what components is this wake_lock helpful for? I am curious about the sound and the socket connection. Will I be able to do this with only a partial wake_lock?

As for the socket connection, will I need an additional wifi lock if it is done under wifi? The socket connection only consists of small transaction once a while, so is there a way that I can have the socket connection not under wifi (even if the user enabled wifi), so I don't have to wifi lock and waste power? or are socket connection conveniently done only under 3g/4g or can gracefully degenerate from wifi to 3g/4g?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流绪微梦 2025-01-11 16:29:34

我是否需要唤醒锁才能让我的应用程序发挥功能

正常?一般来说,是的。 如果您的网络连接是通过移动数据进行的,并且如果您有一个到服务器的开放套接字,并且如果该服务器向您发送数据包,那么短暂唤醒手机。然而,要完成任何严肃的工作,您需要获取一个WakeLock。如果上面的任何斜体 if 语句不成立,那么只要您尝试维持此连接,就需要 WakeLock

因此,请考虑切换到 C2DM 来发送通知。

我可以仅使用部分唤醒锁来做到这一点吗?

部分 WakeLock 就足够了。

如果在wifi下完成,我需要额外的wifi锁吗?

是的。

有没有一种方法可以让套接字连接不在 wifi 下(即使用户启用了 wifi),这样我就不必锁定 wifi 并浪费电力?

并不真地。您请求套接字连接。您可以使用当时处于活动状态的任何网络。

或者套接字连接是否只能在 3g/4g 下方便地完成,或者可以从 wifi 优雅地退化到 3g/4g?

如果 WiFi 断电或因其他原因变得不可用,网络连接会正常恢复到移动数据。然而,套接字连接则不然。如果您在 WiFi 上有套接字连接,并且 WiFi 断电,则您的套接字已关闭,您需要在新网络上重新打开它。

do I need a wake_lock to be able to have my app function

Generally, yes. If your network connection is via mobile data and if you have an open socket to a server and if that server sends packets to you, that will wake up the phone briefly. However, to do any serious work, you need to then acquire a WakeLock. And if any of the italicized if statements from above are not true, then you need a WakeLock as long as you are trying to maintain this connection.

Hence, please consider switching to C2DM for push notifications.

Will I be able to do this with only a partial wake_lock?

A partial WakeLock should suffice.

will I need an additional wifi lock if it is done under wifi?

Yes.

is there a way that I can have the socket connection not under wifi (even if the user enabled wifi), so I don't have to wifi lock and waste power?

Not really. You request the socket connection. You use whatever network is active at the time.

or are socket connection conveniently done only under 3g/4g or can gracefully degenerate from wifi to 3g/4g?

Network connectivity gracefully falls back to mobile data if WiFi powers down or otherwise becomes unavailable. However, socket connnections do not. If you have a socket connection on WiFi, and WiFi powers down, your socket is closed, and you would need to reopen it on the new network.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文