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

UDP Receive

Discussion in 'Android Development' started by EhsanCompanY, Nov 17, 2018.

  1. EhsanCompanY

    EhsanCompanY Lurker
    Thread Starter

    Hi, I'm new to android
    I'm trying to use UDP to send and receive my data
    Code (Java):
    1.   public class sMessage implements Runnable {
    2.         @Override
    3.         public void run() {
    4.             try {
    5.                 DatagramSocket s = new DatagramSocket();
    6.                 InetAddress local = InetAddress.getByName("192.168.16.254");
    7.                 int msg_length=messageStr.length();
    8.                 byte[] message = messageStr.getBytes();
    9.                 DatagramPacket p = new DatagramPacket(message, msg_length,local,server_port);
    10.                 s.send(p);
    11.  
    12.             } catch (IOException e) {
    13.                 Log.e(TAG, "ERROR");
    14.             }
    15.         }
    16.     }
    This code I used is for sending data, but I can't receive data on UDP
    can any one give me a hint how to receive as easy as sending UDP?
     


  2. Best Answer:
    Post #2 by Deleted User, Nov 17, 2018 (3 points)
  3. Deleted User

    Deleted User Guest

    scary alien likes this.
Loading...

Share This Page

Loading...