• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android Datagram Sockets not working

dsgd47

Lurker
I am trying to implement basic Datagram Sockets in Android. I am starting with one of the samples available on the web:
Code:
String messageStr="Hello Android!";
int server_port = 54372;
try {
    DatagramSocket s = new DatagramSocket();
    InetAddress local = null;
    local = InetAddress.getByName("192.168.100.127");
    int msg_length=messageStr.length();
    byte[] message = messageStr.getBytes();
    DatagramPacket p = new DatagramPacket(message, msg_length, local, server_port);
    s.send(p);
} catch (SocketException e) {
    e.printStackTrace();
} catch (UnknownHostException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
I have enables the INTERNET permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>

The program dies when it hits the s.send(p) command.

What am I missing? It must be something obvious.

Thanks,
Dan
 
I am using Datagram sockets because the hardware that I need to communicate with uses the UDP protocol.

There is no error message. I just get the comment that the program has stopped working. That is why I seem to be having so much trouble.
 
Back
Top Bottom