1. Are you ready for the Galaxy S20? Here is everything we know so far!

Send UDP from Application

Discussion in 'Android Development' started by KorenRon, Aug 29, 2019.

  1. KorenRon

    KorenRon Lurker
    Thread Starter

    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 ,
     


    #1 KorenRon, Aug 29, 2019
    Last edited by a moderator: Aug 29, 2019
Loading...

Share This Page

Loading...