Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Damned MulticastSockets

  • 27-06-2007 5: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