Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: UDP packet is not receiving by MUX (Gospell) while using Multicasting in java

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation UDP packet is not receiving by MUX (Gospell) while using Multicasting in java

    import java.net.*;

    public class SendConfig
    {
    InetAddress SYSTEM_IP;
    int SYSTEM_PORT = 5000;
    InetAddress MULTICAST_IP;
    int PORT = 6000;
    int TTL = 1;

    DatagramPacket sendPacket;
    MulticastSocket socket;

    public ststic void main(String[] args)
    {
    new SendConfig().sendUDP();
    }

    SendConfig()
    {
    try
    {
    SYSTEM_IP = InetAddress.getByName("192.168.1.6");
    MULTICAST_IP = InetAddress.getByName("226.1.1.1");
    SocketAddress socket_address = new InetSocketAddress(SYSTEM_IP,SYSTEM_PORT);
    socket = new MulticastSocket(socket_address);
    socket.connect(MULTICAST_IP,PORT);
    NetworkInterface NI = NetworkInterface.getByName("eth0");
    socket.setNetworkInterface(NI);
    socket.setInterface(SYSTEM_IP);
    socket.setTimeToLive(TTL);
    sendUDP(datagram);
    }
    catch(Exception E)
    {
    System.out.println("In Constructor :: "+E);
    }
    }

    void sendUDP()
    {
    byte[] config_datagram = {'h','e','l','l','o'};

    Thread thr = new Thread()
    {
    public void run()
    {

    try
    {
    while(true)
    {
    sendPacket = new DatagramPacket(config_datagram ,config_datagram .length);
    socket.send(sendPacket);
    sleep(1000);
    }
    }
    catch(Exception E)
    {
    System.out.println("in Sending :: "+E);
    }
    }
    };
    thr.start();
    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: UDP packet is not receiving by MUX (Gospell) while using Multicasting in java

    Welcome to the Forum! Please read this topic to learn how to post your code correctly along with other useful info for newcomers.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: UDP packet is not receiving by MUX (Gospell) while using Multicasting in java

    @aayush350: your code, for what I see, should not even compile, because the anonymous inner class for the Thread cannot "see" the local variable config_datagram .... unless it is marked final (and actually it's not so).

    And note also the mispelled:
    public ststic void main(String[] args)
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

Similar Threads

  1. Sending and Receiving Via Tcp And Udp
    By amit1983 in forum Java Theory & Questions
    Replies: 4
    Last Post: December 9th, 2013, 03:56 PM
  2. [SOLVED] Basics With UDP Packet
    By servalsoft in forum Java Networking
    Replies: 0
    Last Post: October 13th, 2011, 12:47 PM
  3. Stop receiving packet from motes
    By gloor in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 29th, 2011, 06:11 PM
  4. How to set the format of a udp packet ?
    By Mezzo in forum Java Networking
    Replies: 0
    Last Post: January 19th, 2011, 06:43 PM
  5. Replies: 6
    Last Post: October 23rd, 2009, 03:53 AM