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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:14:02+00:00 2026-05-27T14:14:02+00:00

I am writing a class in Java which is used to greatly simplify the

  • 0

I am writing a class in Java which is used to greatly simplify the process of multicasting. However, I am having two big problems with it:

  1. The class sends data (I can verify this with my net monitor, Wireshark) but the data is not received by any others in the same group.
  2. On some machines, the sending packet TTL is exceeded in transit (again, according to Wireshark).

Could anyone please help me? I’ve been trying and searching for answers for hours, and it appears that my code follows all of the basic procedures for connecting to, joining, sending, and receiving data from a multicast host.

Here is a snippet of the relevant portions of the class:

Multicaster class:

public class Multicaster {
  public int port = 5540;

  protected String IPAddress;

  private MulticastSocket msConn;
  private InetAddress netAddr;

  public Multicaster(String IPAddress) {
    this.IPAddress = IPAddress;
  }

  public String recieveData() {
    byte[] buf = new byte[1000];
    DatagramPacket pack = new DatagramPacket(buf, buf.length);

    try {
      this.msConn.receive(pack);
      new Message(pack);
      String out = new String(pack.getData());
      return out.substring(0, pack.getLength());
    } catch (IOException e) {
      return new String("");
    }
  }

  public void joinGroup() { 
    try {
      this.msConn.joinGroup(this.netAddr);
    } catch (IOException e) {
    //This error shouldn't occur since it would caught by the connect() method during initial connection to the host
    }
  }

  public void connect() throws MulticasterInitException {
  //Try to create a multicast connection on the given IP address and port
    try {
      try {
      //Create a multicast connection on a given port, throws UnknownHostException
        this.msConn = new MulticastSocket(this.port);

      //If all goes well, then create a connection to a given IP address using the above port number, throws IOException and SecurityException
        this.netAddr = InetAddress.getByName(this.IPAddress);
      }
    }

  /**
   * Here all of the possible exceptions that are thrown above
   * are caught and handled here. This works just fine.
   */
  }

  public void sendData(String data) throws MulticasterSendException {
    DatagramPacket packet = new DatagramPacket(data.getBytes(), data.length(), this.netAddr, this.port);

    try {
      this.msConn.send(packet);
    } catch (IOException e) {
      throw new MulticasterSendException("Java could not communicate with the server. Please check your network connections.", e);
    }
  }
}

Sample usage to send data:

Multicaster multicast = new Multicaster("239.0.0.0");

try {
  multicast.connect();
} catch (MulticasterInitException e) {
  //Handle exception...
}

multicast.joinGroup();

try {
  multicast.sendData("Hi");
} catch (MulticasterSendException e) {
  //Handle exception... 
}

Sample usage to receive data:

Multicaster multicast = new Multicaster("239.0.0.0");

try {
  multicast.connect();
} catch (MulticasterInitException e) {
  //Handle exception...
}

multicast.joinGroup();
System.out.print(multicast.recieveData());
  • 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-27T14:14:02+00:00Added an answer on May 27, 2026 at 2:14 pm

    I’ve run into similar problems before and had to ensure that the NetworkInterface was specified on the receiving side.

    SocketAddress socketAddress = new InetSocketAddress(groupIp, groupPort);
    NetworkInterface networkInterface = NetworkInterface.getByName(interfaceName);
    
    socket.joinGroup(socketAddress, networkInterface);
    

    Where interfaceName is one of the interface names shown when running ifconfig on Linux or Mac.

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

Sidebar

Related Questions

I am writing a class in Java to simplify the process of connecting to,
I am writing a class in Java to simplify the process of connecting to,
I am writing a Xml Tag Renamer class with Java which reads in a
In Netbeans IDE i am writing a java class which has some method. One
I'm writing a Java class which plugs into a larger framework. Somewhere upstream, the
Is there a C or C++ compatible library for reading and writing Java class
I was writing a toString() for a class in Java the other day by
I have some experience writing web applications in Java for class projects. My first
I'm writing an app for Java ME, and I need a class for holding
I am considering starting a project which is used to generate code in Java

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.