0

hi i tried running the code below as the server:

public static void main(String args[]) 
    {
        DatagramSocket socket = new DatagramSocket(); //construct a datagram socket and binds it to the available port and the localhos

        byte[] b = new byte[32];    //creates a variable b of type byte
        DatagramPacket dgram;

        dgram = new DatagramPacket(b, b.length, InetAddress.getByName("235.1.1.1") , 7777);//sends the packet details, length of the packet,destination address and the port number as parameters to the DatagramPacket  
        //dgram.setData(b);
        System.err.println("Sending " + b.length + " bytes to " + dgram.getAddress() + ':' + dgram.getPort());//standard error output stream


        while(true) {
          System.err.print(".");
          socket.send(dgram); //send the datagram packet from this port
          Thread.sleep(1000); //cause the current executed thread to sleep for a certain number of miliseconds
        }

and client as :

    public static void main(String args[]) throws IOException
    {
        byte[] b = new byte[011];
        DatagramPacket dgram = new DatagramPacket(b, b.length);
        MulticastSocket socket = new MulticastSocket(7777); // must bind receive side
        socket.joinGroup(InetAddress.getByName("235.1.1.1"));

        while(true) {
          socket.receive(dgram); // blocks until a datagram is received
          System.err.println("Received " + dgram.getLength() +
            " bytes from " + dgram.getAddress());
          dgram.setLength(b.length); // must reset length field!s
    }
    }

when i run the client it says that " Exception in thread main java.net.SocketException : not a multicast address at java...
"
does anyine knows the reason for this
any comments

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by anisha.silva
0

Can you post code that compiles and executes and shows the problem.

Also please post the full text of the error message.

0

the error is not coming any more what sould be the out put if it were to run correclty, is it in the server end:
Sending 32 bytes to /235.1.1.1:7777
..............................................

and client end:
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105
Received 9 bytes from /192.168.1.105

0

Is the program working correctly now? If not please explain.

Can you provide working code for testing if you want help?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.