Start New Discussion within our Software Development Community

hello frndz,
i was trying to implement a client server communication example.her's the code

import java.net.*;
class client_server_communication
{
   private static int client_port=4444;
   private static int server_port=4476;
   private static int buffer_size=1024;
   private static byte[] buffer=new byte[buffer_size];
   private static DatagramSocket ds;
   private static byte buff[]=new byte[buffer_size];
   public static void server() throws Exception
   {
      int pos=0;
      int c;
	  while(true)
	  {
	  c=System.in.read();
	  switch(c)
	  {
	     case -1:
		 System.out.println("server quits.");
		 return;
		 case '\n':
		 ds.send(new DatagramPacket(buffer,pos,InetAddress.getLocalHost(),client_port));
		 pos=0;
		 break;
		 default:
		 buffer[pos++]=(byte)c;
	  }
	  }
   }
   public static void client() throws Exception
   {
      while(true)
	  {
	     DatagramPacket d1=new DatagramPacket(buff,buffer.length);
		 ds.receive(d1);
		 System.out.println(d1);
	  }
   }
   public static void main(String p[]) throws Exception
   {
      ds=new DatagramSocket(server_port);
      if(p.length==1)
	  server();
	  else
	  System.out.println("hi");
	  client();
   }
}

But,i got this exception
java.net.SocketException:unrecognized windows sockets error
i tried it with different port numbers but,same exception occurred either on client side or server side......plz help

When do you get the error? Which programs do you execute in what order?
What line of code does the error occur on?

This article has been dead for over six months. Start a new discussion instead.