clientu.java 787 B

1234567891011121314151617181920212223242526272829303132
  1. import java.io.*;
  2. import java.net.*;
  3. public class clientu{
  4. public static void main(String arg[])throws IOException
  5. {
  6. try
  7. {
  8. DatagramSocket clientsock=new DatagramSocket();
  9. byte[] send;
  10. byte[] recv = new byte[1024];
  11. BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  12. String str=br.readLine();
  13. String rec;
  14. InetAddress ip=InetAddress.getByName("localhost");
  15. send=str.getBytes();
  16. DatagramPacket sendpacket= new DatagramPacket(send,send.length,ip,9090);
  17. clientsock.send(sendpacket);
  18. DatagramPacket recvpacket=new DatagramPacket(recv,recv.length);
  19. clientsock.receive(recvpacket);
  20. rec=new String(recvpacket.getData(),0,recvpacket.getLength());
  21. System.out.println(""+rec);
  22. }
  23. catch(Exception e)
  24. {
  25. System.out.println(""+e);
  26. }
  27. }
  28. }