Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#10 HTTPMUSocket.send doesn't multicast to correct address:port

open
Satoshi Konno
5
2004-01-17
2003-11-29
Tim Malcolm
No

Testing with the Intel Device Validator shows that
Cyberlink's notify messages are never received by the
Device Validator.

Problem: HTTPMUSocket.send(..) method does not use a
valid SSDP mutlicast address.

Solution: ensure messages with "null" bind address and "-
1" bind port are sent to multicast address and
port "239.255.255.250:1900"

Tested: partial, on JDK 131

Code: HTTPMUSocket.send method below - sorry, no
diffs, just the complete method is reproduced here:

public boolean send(String msg, String bindAddr, int
bindPort)
{
try {

if (bindAddr == null) bindAddr = SSDP.ADDRESS;
if (bindPort < 0) bindPort = SSDP.PORT;

InetAddress mgroup = InetAddress.getByName(bindAddr);
MulticastSocket msock = new MulticastSocket(bindPort);
if ((bindAddr) != null && (0 < bindPort))
msock.setInterface(InetAddress.getByName(bindAddr));
msock.joinGroup(mgroup);
DatagramPacket dgmPacket = new DatagramPacket
(msg.getBytes(), msg.length(),
mgroup, bindPort);
msock.send(dgmPacket);
msock.leaveGroup(mgroup);

}
catch (Exception e) {
Debug.warning(e);
return false;
}
return true;
}

Discussion

  • Tim Malcolm
    Tim Malcolm
    2003-12-01

    Logged In: YES
    user_id=604843

    I didn't test the code above properly.

    The line
    if ((bindAddr) != null && (0 < bindPort))
    is redundant and can be removed.

    The line
    msock.setInterface(InetAddress.getByName(bindAddr));
    causes an exception and must be removed.

     
  • Tim Malcolm
    Tim Malcolm
    2003-12-01

    Logged In: YES
    user_id=604843

    I didn't test the code above properly.

    The line
    if ((bindAddr) != null && (0 < bindPort))
    is redundant and can be removed.

    The line
    msock.setInterface(InetAddress.getByName(bindAddr));
    causes an exception and must be removed.

     
  • Satoshi Konno
    Satoshi Konno
    2003-12-15

    Logged In: YES
    user_id=559351

    Hi Tim

    I checked your codes with the Intel Device Validator . Thanks
    for your effrot :-)

    I changed the HTTPMUSocket::send() as the following and
    release the package as v 1.2.
    Please check it :-)

    public boolean send(String msg, String bindAddr, int bindPort)
    {
    try {
    MulticastSocket msock;
    if ((bindAddr) != null && (0 < bindPort)) {
    msock = new MulticastSocket(null);
    msock.bind(new InetSocketAddress(bindAddr, bindPort));
    }
    else
    msock = new MulticastSocket();
    DatagramPacket dgmPacket = new DatagramPacket
    (msg.getBytes(), msg.length(), ssdpMultiGroup);
    msock.send(dgmPacket);
    msock.close();
    }
    catch (Exception e) {
    Debug.warning(e);
    return false;
    }
    return true;
    }

    The bindAddr and bindPort are local interface address and
    port, and the multicast doesn't have to
    join the multicast network for sending. Please check the
    following document.

    Java2 Platform SE Document (MulticastSocket)
    http://java.sun.com/j2se/1.4.1/docs/api/java/net/MulticastSo
    cket.html
    When one sends a message to a multicast group, all
    subscribing recipients to that host and port receive the
    message (within the time-to-live range of the packet, see
    below). The socket needn't be a member of the multicast
    group to send messages to it.

     
  • Satoshi Konno
    Satoshi Konno
    2004-01-17

    • assigned_to: nobody --> skonno
     
  • Rembo
    Rembo
    2005-04-19

    Logged In: YES
    user_id=1262118

    the joingroup and leavegroup is not necessary for sending to
    a multicast group. Moreover I have noticed that this can
    cause trouble when running under linux and using a firewall.

     
  • Rembo
    Rembo
    2005-04-19

    Logged In: YES
    user_id=1262118

    Ummm, ok. Next time I'll first read all the comments before
    posting.