How to work with UDP in Android?
I am very new to the Android platform. I need to make a connection with a UDP server by using my Android UDP client. Now, I need to know how to work with UDP in Android. Please guide me to do thi开发者_JAVA百科s.
You can work with UDP in Android applications just like in any Java app, with java.net.DatagramSocket
and java.net.DatagramPacket
. There's a short sample app available at http://www.anddev.org/udp-networking_-_within_the_emulator-t280.html
In my experience working with UDP on Android is similar to working with UDP on a normal Java application. Follow the example above and you should be okay. However, I would recommend that you do most of your testing on an actual device (if you have access to one) instead of the emulator. It took me some time to figure out that the emulator (at least the version I used) has a packet size limitation of about 8K.
精彩评论