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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:18:20+00:00 2026-05-27T05:18:20+00:00

My server creates a multicast socket which listens for UDP packets. It is receiving

  • 0

My server creates a multicast socket which listens for UDP packets. It is receiving packets sent to the broadcast address of the network but I can’t get the ip address of the sender:

multisocket.getInetAddress().getHostAddress();

returns

"::" 

(I guess its because of null getInetAddress).

How can I get the IP address of the sender?

TIPS: I guess it has to do with the socket not being bound and basically the whole broadcasting because those packets arent sent exclusively to me but to the whole network, but shouldnt they hold the IP address of the sender? Enlighten me please.

Here is the code:

public void run() {
    try {
        Thread.sleep(5000);
        Log.i("SERVERUDP", "Connecting...");
        MulticastSocket multisocket = new MulticastSocket(SERVERPORT);
        multisocket.setBroadcast(true);
        Log.i("SERVERUDP","Server's IP is: " + multisocket.getLocalAddress().getHostAddress());
        getLocalIpAddress();
        while(true){
            byte[] b = new byte[65535];
            ByteArrayInputStream b_in = new ByteArrayInputStream(b);
            DatagramPacket dgram = new DatagramPacket(b, b.length);
            multisocket.receive(dgram); // blocks
            ObjectInputStream o_in = new ObjectInputStream(b_in);
            Object o = o_in.readObject();
            dgram.setLength(b.length);
            b_in.reset();
            if(o.getClass().getSimpleName().equalsIgnoreCase("Request")){
                Request request = (Request)o;
                String inetaddress = multisocket.getInetAddress().getHostAddress();
                Log.i("SERVERUDP-if", "Sending request to IP: " + inetaddress);
                new Thread(new ClientTCP(inetaddress, createRequestFromBroadcast(request))).start();
            }else if(o.getClass().getSimpleName().equalsIgnoreCase("String")){
                Log.e("SERVERUDP-elseif-string", "WTF received a string: " + (String)o);
            }else{
                Log.e("SERVERUDP-else", "Unrecognized object of type: " + o.getClass().getSimpleName());
            }
            o_in.close();
            //iteration done only once for testing!
            break;
        }
        multisocket.close();
    } catch (Exception e) {
        Log.e("SERVERUDP", "Error", e);
    }
}
  • 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-27T05:18:21+00:00Added an answer on May 27, 2026 at 5:18 am

    Each packet that you receive might have a different source address. So I’m not sure why you’re trying to look at multisocket to figure out the source address.

    I have to admit I haven’t tried this, but does dgram.getSocketAddress () give you what you want after the multisocket.receive call returns?

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

Sidebar

Related Questions

I'm writing a server in C# which creates a (long, possibly even infinite) IEnumerable<Result>
CruiseControl.net creates (by default) for each project a subdirectory under: c:\Program File\CruiseControl.NET\server How can
I'm writing http session manager (gen_server based). That server creates and removes session from
I have to write a component that re-creates SQL Server tables (structure and data)
I've written a simple multi-threaded game server in python that creates a new thread
I understand that CoCreateInstance finds the COM server for the given class id, creates
Server has created a socket and bound to a port and started a thread
after progress on the question how to create socket.io multicast groups , I found
I'm trying to write some python code which can create multipart mime http requests
I need some help with finding network interfaces based on a provided IP address.

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.