You need a try catch block in order to catch the exception being thrown 
. . .
I added one just to get teh code to compile but you will have to take a 
closer look at the code to see where you want to place it.

I tried to bold the additions. Good luck. . .
****************************************************

import java.net.*;

public class MulticastChatServer {

    public static void main(String[] args) {
        // throws Exception    //error is here "Illegal start of 
expression.and ";" is needed
*        try {*
            int portnumber = 1236;
            if (args.length >= 1) {
                portnumber = Integer.parseInt(args[0]);
            }
            MulticastSocket serverMulticastSocket = new 
MulticastSocket(portnumber);
            System.out.println("MulticastSocket is created at port " + 
portnumber);
            InetAddress group = InetAddress.getByName("224.0.0.1");
            serverMulticastSocket.joinGroup(group);
            System.out.println("joinGroup method is called...");
            boolean infinite = true;
            while (infinite) {
                byte buf[] = new byte[1024];
                DatagramPacket data = new DatagramPacket(buf, buf.length);
                serverMulticastSocket.receive(data);
                String msg = new String(data.getData()).trim();
                System.out.println("Message received from client = " + msg);
            }
            serverMulticastSocket.close();
        }* catch (Exception e) {
            e.printStackTrace();*
        }
    }
}

****************************************************


pradeepan patra wrote:
> hiiiiii friends
>
> Can anyone say me what is the error in this code
>
> import java.net.*;
> public class MulticastChatServer
>     {
>       public static void main(String[] args)
>         {
>               throws Exception    //error is here "Illegal start of 
> expression.and ";" is needed
>             {
>                  int portnumber = 1236;
>                  if (args.length >= 1)
>                 {
>                     portnumber = Integer.parseInt(args[0]);
>                 }
>              MulticastSocket serverMulticastSocket =new 
> MulticastSocket(portnumber);
>              System.out.println("MulticastSocket is created at port 
> "+portnumber);
>              InetAddress group=InetAddress.getByName("224.0.0.1");
>              serverMulticastSocket.joinGroup(group);
>              System.out.println("joinGroup method is called...");
>              boolean infinite = true;
>              while(infinite)
>                 {
>                  byte buf[] = new byte[1024];
>                  DatagramPacket data =new DatagramPacket(buf, buf.length);
>                  serverMulticastSocket.receive(data);
>                  String msg =new String(data.getData()).trim();
>                  System.out.println("Message received from client = " 
> + msg);
>                 }
>                     serverMulticastSocket.close();
>             }
>         }
>     }
>
> >

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to