tags:

views:

4

answers:

0
import java.net.*;
import java.io.*;
class democlientUDP
{


 public static void main(String[] args) throws Exception
 {
  DatagramSocket asock=new DatagramSocket();
  byte []buf=args[0].getBytes();
  int serverport=1234;
  InetAddress a=InetAddress.getByName("127.0.0.1");
  DatagramPacket req=new DatagramPacket(buf,buf.length,a,serverport);
  asock.send(req);
 }
}




import java.net.*;
import java.io.*;
class demoserverUDP
{


 public static void main(String[] args) throws Exception
 {
  DatagramSocket asock=new DatagramSocket(1234);
  byte []buf=new byte[1000];
  DatagramPacket req=new DatagramPacket(buf,buf.length);
  asock.receive(req);
  System.out.println("Hello World!"+new String(req.getData()));
 }
}

I am writing a java program to send a UDP packet to server and then the server should display? the problem is that when i send a message from the client to server the server is not displaying the message. Is there any thing wrong in the code if so corrent it ?