MulticastSocket not receiving

P

paul brown

Hi

I've got a simple MulticastSocket program which is not able to receive any
data for some reason.

Here's the relevant code for the listener:

final int port = 5555;
final String group = "225.4.5.6";
final int ttl = 5;

Runnable r2 = new Runnable(){
public void run(){
try{
MulticastSocket r = new MulticastSocket(port);
r.joinGroup(InetAddress.getByName(group));
byte[] buf =
new byte[10];
DatagramPacket pack =
new DatagramPacket(buf, buf.length);
r.setSoTimeout(5000);
pack.setLength(10);

while(!m_pleaseStop){
System.out.println("Trying to receive 10
bytes...");

try{
r.receive(pack);
}
catch(SocketTimeoutException se){
continue;
}

System.out.println("Received data from: " +
pack.getAddress().toString() +
":" + pack.getPort() + " with
length: " +
pack.getLength());

System.out.write(pack.getData(),0,pack.getLength());
System.out.println();
}

r.leaveGroup(InetAddress.getByName(group));
r.close();
}
catch(Throwable th){
th.printStackTrace();
}
}
};


I also have a sender which looks like this:

Runnable r1 = new Runnable(){
public void run(){
try{
MulticastSocket s =
new MulticastSocket();

byte[] buf = "192.168.1.1:8888".getBytes();
DatagramPacket pack =
new DatagramPacket(buf, buf.length,
InetAddress.getByName(group),
port);

System.out.println("Sending " +
new String(buf));

while(!m_pleaseStop){
s.send(pack,(byte)ttl);

Thread.sleep(5000);
}

s.close();
}
catch(Throwable th){
th.printStackTrace();
}
}
};


Using a packet sniffer i can see that the packets are getting sent out but i
never get anything back in through the receive() call.

When i do a 'netstat -an' the 5555 port is listed under 0.0.0.0/0.0.0.0 and
not the multicast group i'd expect (i think)...

I'm running an DLink - 504 ADSL router which i think is Multicast capable
(not sure if that's even relevant).

I'm also running the MS Loopback adapter (on Win2K).

Using JDK 1.4.2_0.2

Has anyone got any suggestions?

Thanks,
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top