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 7278227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:50:46+00:00 2026-05-28T22:50:46+00:00

I’m developing a UDP responder to handle basic SSDP commands. The purpose of this

  • 0

I’m developing a UDP responder to handle basic SSDP commands. The purpose of this piece of code is to do auto discovery, so when the server sends a multicast to a specific group all other subscribed devices should send back a UDP packet announcing its presence to the host and port of who sent the multicast. My android device receives and sends the packet just fine but because it takes too long to get back the SocketAddress object from getSocketAddress() method the server times out, closes the listening port and never gets a packet back from the android device.

Here’s my code:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MulticastSocket ms = null;
    byte[] packBuf = new byte[128];
    try {
        ms = new MulticastSocket(32410);
        ms.joinGroup(InetAddress.getByName("239.255.255.250"));
    } catch (IOException e3) {
        // TODO Auto-generated catch block
        e3.printStackTrace();
    }

    while (true)
    {
        DatagramPacket receivedPack = new DatagramPacket(packBuf, packBuf.length);
        try {
            ms.receive(receivedPack);
            Log.d(TAG, "Received data");

        } catch (IOException e3) {
            // TODO Auto-generated catch block
            e3.printStackTrace();
        }

        String responseStr = "HTTP/1.0 200 OK\n" + 
           "Content-Type: app\n" + 
           "Resource-Identifier: 945e7dd5913ab45f1db4f271a1620b9471fb7d4d\n" +
           "Name: Test App\n" +
           "Port: 8888\n" + 
           "Updated-At: 1319511680\n" +
           "Version: 0.9.3.4-29679ad\n" +
           "Content-Length: 23\n\n" + 
           "<message>test</message>";

        byte[] response = responseStr.getBytes();

        DatagramSocket sendSocket = null;
        try {
            sendSocket = new DatagramSocket();

        } catch (IOException e2) {
            // TODO Auto-generated catch block
            Log.e(TAG,"Erro",e2);
        }

        DatagramPacket outPack;
        try {
            outPack = new DatagramPacket(response, responseStr.length(), receivedPack.getSocketAddress());
            sendSocket.send(outPack);
        } catch (UnknownHostException e1) {
            Log.e(TAG,"Erro",e1);
        }
        catch (IOException e) {
            Log.e(TAG,"Erro",e);
        }
        catch (Exception e)
        {
            Log.e(TAG,"Erro",e);
        }
    }
}

Any ideas?

thanks in advance,

fbr

  • 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-05-28T22:50:46+00:00Added an answer on May 28, 2026 at 10:50 pm

    2 things come to mind…

    1) What happens when you change:

    outPack = new DatagramPacket(response, responseStr.length(), receivedPack.getSocketAddress());
    

    to

    outPack = new DatagramPacket(response, responseStr.length(), receivedPack.getAddress(), receivedPack.getPort());
    

    2) I remember having this sort of problem with an embedded Java on a Home Automation system. Our short term solution was to put most of the machine and multicast addresses in the hosts file. Long term we ended up with a local DNS server.

    There is a parameter somewhere in the Java Network stack that tells it how long to cache DNS failures in memory. We cranked that number up to, I think, 5 minutes instead of 10 seconds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6

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.