Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > MulticastSocket not receiving

Reply
Thread Tools

MulticastSocket not receiving

 
 
paul brown
Guest
Posts: n/a
 
      01-22-2004
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






 
Reply With Quote
 
 
 
 
paul brown
Guest
Posts: n/a
 
      01-26-2004
anyone got any thoughts on this?

i'm still strugglign with it ...

thanks
Paul



"paul brown" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-26-2004
"paul brown" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| anyone got any thoughts on this?

Perhaps an SSCCE can entice the reticent..
http://www.physci.org/codes/sscce.jsp
And if it's an applet, the URL..

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Broadcasting in Java but NOT MulticastSocket CS Java 2 06-28-2010 02:41 AM
Broadcasting in Java but NOT MulticastSocket CS Java 3 06-26-2010 07:54 PM
Non-Blocking receive on MulticastSocket Ale Java 7 01-16-2007 05:38 PM
MulticastSocket.send blocks for more than 28 secs on solaris Suresh Java 3 12-09-2005 06:01 PM
Need help with Java MulticastSocket rick Java 16 12-08-2005 02:37 AM



Advertisments