LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-31-2006, 08:50 AM   #1
champ
Member
 
Registered: Jul 2002
Distribution: Slackware 10.0
Posts: 46

Rep: Reputation: 16
java multicast - problems receiving packets


Hey guys. I have a bit of trouble with java multicast. The problem is that the receiving program never reveives anything. It just blocks on multicastSocket.receive(packet). The code below is just an example I found. So it should work. But it doesn't for me. Anyone know why it might block on receive(), even though packets is sent.

Any help is appreciated.


Multicast Send
Code:
// Which port should we send to
    int port = 5000;
    // Which address
    String group = "225.4.5.6";

    
    // Create the socket but we don't bind it as we are only going to send data
    MulticastSocket s = new MulticastSocket();
    
    // Note that we don't have to join the multicast group if we are only
    // sending data and not receiving
    
    // Fill the buffer with some data
    byte buf[] = new byte[10];
    for (int i=0; i<buf.length; i++) buf[i] = (byte)i;
    // Create a DatagramPacket 
    DatagramPacket pack = new DatagramPacket(buf, buf.length,
            InetAddress.getByName(group), port);
    
    
    s.send(pack);
    System.out.println("packet sent");
    
    // And when we have finished sending data close the socket
    s.close();
Multicast receive
Code:
// Which port should we listen to
    int port = 5000;
    // Which address
    String group = "225.4.5.6";
    
    // Create the socket and bind it to port 'port'.
    MulticastSocket s = new MulticastSocket(port);
    
    // join the multicast group
    s.joinGroup(InetAddress.getByName(group));
    // Now the socket is set up and we are ready to receive packets
    
    // Create a DatagramPacket and do a receive
    byte buf[] = new byte[1024];
    DatagramPacket pack = new DatagramPacket(buf, buf.length);
    System.out.println("Before receive");
    s.receive(pack);
    // it never reaches here
    

    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();
    

    // close the socket
    s.leaveGroup(InetAddress.getByName(group));
    s.close();
 
Old 05-31-2006, 09:32 AM   #2
champ
Member
 
Registered: Jul 2002
Distribution: Slackware 10.0
Posts: 46

Original Poster
Rep: Reputation: 16
I have a multicast program written in C and the same thing happened. It just blocks on receive.... So im presuming it has nothing to do with the code...maybe my system is blocking multicast of some sort.......hmmmmm
 
Old 05-31-2006, 10:33 AM   #3
champ
Member
 
Registered: Jul 2002
Distribution: Slackware 10.0
Posts: 46

Original Poster
Rep: Reputation: 16
STUPID me....it was my firewall blocking multicast....problem solved
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Synaptic keeps telling me it couldnt download certian packets.IT refuses java Lord Hakk Linux - Software 2 04-11-2006 01:10 PM
recv() fails, tcp dump says i'm receiving isakmp packets rdarbin Linux - Networking 0 12-21-2005 12:06 PM
multicast and iptables problems on SuSE 9.2 rickwood42 Linux - Networking 2 05-31-2005 08:52 PM
making java applets send packets videoediting Programming 4 05-03-2005 01:48 PM
Only receiving UDP packets, no TCP erevlehdeux Linux - Networking 1 04-23-2004 07:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration