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

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

Also please post the full text of the error message.

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

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

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

i think so

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.