1234567891011121314151617181920212223242526272829303132 |
- import java.io.*;
- import java.net.*;
- public class clientu{
- public static void main(String arg[])throws IOException
- {
- try
- {
- DatagramSocket clientsock=new DatagramSocket();
- byte[] send;
- byte[] recv = new byte[1024];
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- String str=br.readLine();
- String rec;
- InetAddress ip=InetAddress.getByName("localhost");
- send=str.getBytes();
- DatagramPacket sendpacket= new DatagramPacket(send,send.length,ip,9090);
- clientsock.send(sendpacket);
- DatagramPacket recvpacket=new DatagramPacket(recv,recv.length);
- clientsock.receive(recvpacket);
- rec=new String(recvpacket.getData(),0,recvpacket.getLength());
- System.out.println(""+rec);
-
- }
- catch(Exception e)
- {
- System.out.println(""+e);
- }
- }
- }
|