Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8284287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:03:04+00:00 2026-06-08T11:03:04+00:00

I am trying to send DatagramPackets (UDP) in my Android application: //create a byte

  • 0

I am trying to send DatagramPackets (UDP) in my Android application:

//create a byte to receive data
mClientSocket = new DatagramSocket();
byte[] receiveData = new byte[MAX_RECEIVE_DATA_SIZE_BYTES];
DatagramPacket receivePacket = new DatagramPacket(receiveData,
        receiveData.length);

// Set a receive timeout
mClientSocket.setSoTimeout(timeout);

// receive the packet
mClientSocket.receive(receivePacket);

return new String(receivePacket.getData(), 0,
        receivePacket.getLength());

I get the following error:

Try again

Am I missing something here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:03:05+00:00Added an answer on June 8, 2026 at 11:03 am

    Well to send the UDP you’d need something similar to:

    Server:

    String  messageStr="Hello Android!";
    int server_port = 12345;
    DatagramSocket  s = new DatagramSocket ();
    InetAddress  local = InetAddress .getByName("192.168.1.102");
    int msg_length=messageStr.length();
    byte[] message = messageStr.getBytes();
    DatagramPacket  p = new DatagramPacket (message, msg_length,local,server_port);
    s.send(p);
    

    Client:

    String  text;
    int server_port = 12345;
    byte[] message = new byte[1500];
    DatagramPacket  p = new DatagramPacket (message, message.length);
    DatagramSocket  s = new DatagramSocket (server_port);
    s.receive(p);
    text = new String (message, 0, p.getLength());
    Log.d("Udp tutorial","message:" + text);
    s.close();
    

    References:

    • Simple UDP communication example
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a UDP client on an android tablet. The application can
I'm trying to create a datagramsocket with and datagrampacket to send with the keep-alive
Im trying to send multiple data items over a tcp socket from an android
I'm trying to create a sever application on PC for many android devices using
I`m trying to send simple html page with form data to user with GET,
I am trying to send data as a model from an html form to
I'm trying to send a UDP datagram (containing a protocol buffers message) and getting
I am trying to send an image over UDP using JAVA. I have managed
Trying to send some data form my previous ViewController. To be more clear trying
I'm trying to send a very basic XML string from a Windows Phone application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.