I have the following very primitive code running in the emulator:
Using java Syntax Highlighting
- try {
- int bufSize = 4096;
- DatagramSocket sock = new DatagramSocket(port);
- sock.setReceiveBufferSize(bufSize);
- byte[] buffer = new byte[bufSize];
- while (true) {
- DatagramPacket p = new DatagramPacket(buffer, bufSize);
- sock.receive(p);
- Log.d("Client", "Received: " + new String(p.getData()));
- }
- ...
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
And I'm using the following code to send packets into the emulator:
Using java Syntax Highlighting
- DatagramSocket sock = new DatagramSocket();
- DatagramPacket packet = new DatagramPacket(
- msg.getBytes(),
- msg.getBytes().length,
- InetAddress.getByName(addr),
- port);
- sock.send ( packet );
- System.out.println ("Sent " + msg + " to " + addr +":" + port);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
I'm invoking this with something like 'java UDPSenderHarness 127.0.0.1 35123"Hello, Android"
, so localhost, and port 35123
My app's manifest specifies internet with :
Using xml Syntax Highlighting
- <uses-permission android:name="android.permission.INTERNET" />
- </manifest>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
Can anyone shed some light on why I'm not receiving UDP data into the emulator?
Thanks,
Mick


