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

Send UDP from Application

KorenRon

Lurker
Hello ,
I'm new at android\java so be patient :)

I want to create a small application that send a udp string to my server when I press the button.
everything is working - but it doesn't seem to send
this is what I have

btnAction.setOnClickListener(new View.OnClickListener() {
@ override
public void onClick(View v) {

try {

String messageStr = "test!";
int server_port = 1111;
DatagramSocket s = new DatagramSocket();
InetAddress local = InetAddress.getByName("My.Public.Server.IP");
int msg_length = messageStr.length();
byte[] message = messageStr.getBytes();
DatagramPacket p = new DatagramPacket(message, msg_length, local,server_port);
s.send(p);
}
catch (Exception e) {

}



}
}

whant could be the reason for it?

Thanks ,
 
Last edited by a moderator:
Back
Top Bottom