Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Damned MulticastSockets

  • 27-06-2007 06:51PM
    #1
    Closed Accounts Posts: 17,208 ✭✭✭✭


    Just doing some playing with MulticastSockets in Java for my own experience, but I'm damned if I can get them to work at all.

    Every bit of documentation I can see about them says that all you have to do is create the object, join the group and send the data. Simple enough.

    My problem is that though I'm following that, I can't seem to get it working.
    InetAddress netAddress = InetAddress.getByName("239.255.255.250");
    MulticastSocket mconn = new MulticastSocket(1900);
    mconn.setTimeToLive(4);
    mconn.joinGroup(netAddress);
    
    String message = "stuff";
    DatagramPacket datagram = new DatagramPacket(message.getBytes(), message.length());
    mconn.send(datagram);
    

    However, if I run that I'm getting a NullPointerException: null address || null buffer from the MulticastSocket.

    Any ideas?


Comments

  • Registered Users, Registered Users 2 Posts: 4,188 ✭✭✭pH


    Your current issue seems to be how you're creating the datagram packet:

    Change this:
    DatagramPacket datagram = new DatagramPacket(message.getBytes(), message.length());
    

    to :
    DatagramPacket datagram = new DatagramPacket(message.getBytes(), message.length(), netAddress, port);
    


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    D'oh, right you are. Cheers.


Advertisement