Android phone development - UDP services

旧巷老猫 提交于 2019-12-06 05:41:11

问题


I'm interested in the viability of implementing an Android application that interacts with a UDP service. I'm sure Android supports UDP:

http://www.helloandroid.com/tutorials/simple-udp-communication-example

What I'm less clear about is whether or not such an application would actually work on an Android phone on a typical tariff - for bidirectional communication. I want the Android client to contact a remotely hosted service by UDP (announcing itself) and for the server to subsequently notify the Android device about real-time events.

I'm concerned that a mobile device on a commercial network might be forced to change IP address - for example - when moving in/out of a Wi-Fi zone... and I'm unclear if NAT would be a problem on a typical 3G network.

Is it really viable to use UDP for bi-directional (best-effort) communications both to and from an Android phone?


回答1:


There are a few issues for you to look at here. First, UDP is perfectly useable by Android. It can send and receive UDP packets just fine. The larger issue is really that the phone cannot receive incoming UDP connections that it did not open the initial connection for, unless it is on WiFi and rhe connection is coming from the same LAN.

On 3G/4G the phone is not addressable from the outside because the Wireless carrier has in place a firewall with a proxy server. So, incoming connections are not passed over that firewall. If, instead the phone opens the connection from behind the firewall, then bidirectional traffic can flow over that link.

Now, the problem you will have will be

1) Keeping the link alive when the phone goes from network (3G) to network (Wifi)

2) Battery life from the constantly open connection

Most likely, you really want C2DM for what you are looking at.



来源:https://stackoverflow.com/questions/8401481/android-phone-development-udp-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!