You are on page 1of 2

import java.io.

*;

and output through data streams, serialization and the file system.
import java.net.*;//Provides

//Provides for system input

the classes for

implementing networking applications.


public class udpclient { public static void main(String args[]) { String se; try { DatagramSocket s=new DatagramSocket();//create a socket for sending and receiving datagram packets do { data");//print the message System.out.println("Enter the

DataInputStream in=new DataInputStream(System.in);//receive the data from the system InetAddress ipa=InetAddress.getByName("192.168.2.31"); //represents the ip address byte[] sdata=new byte[1024]; //array for send packet data byte[] rdata=new byte[1024];//array for received packet data se=in.readLine(); sdata=se.getBytes(); System.out.println("vi micro"+se); DatagramPacket spack=new DatagramPacket(sdata,sdata.length,ipa,9876); s.send(spack);

DatagramPacket(rdata,rdata.length);

DatagramPacket rpack=new s.receive(rpack); String modse=new

String(rpack.getData()); "+modse); } while(!se.equalsIgnoreCase("End")); s.close(); } catch(Exception e) { System.out.println("Error:"+e); } } } System.out.println("From server :

You might also like