DatagramClent.java
import java.net.*; import java.io.*;
class DatagramClient { public static DatagramSocket ds; //Used to create the socket for communication public static byte buffer[]=new byte[1024];
public static int clientport=789, serverport=790; //communication ports
public static void main(String args[]) throws Exception { ds=new DatagramSocket(clientport); //socket open on client port
System.out.println("Client is waiting for servder to send data"); System.out.println("Press Ctrl+C to come out"); while(true) { DatagramPacket dp=new DatagramPacket(buffer, buffer.length); //packets for receive the message ds.receive(dp); //receive packets String pdata=new String(dp.getData(),0, dp.getLength()); System.out.println(pdata); } } }
DatagramServer.java
import java.net.*; import java.io.*;
class DatagramServer { public static DatagramSocket ds; //used to create socket for communication public static int clientport=789, serverport=790; //
public static void main(String args[]) throws Exception { byte buffer[]=new byte[1024]; ds=new DatagramSocket(serverport); //opens the socket on server port
BufferedReader breader=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Server is waiting for input"); InetAddress inet=InetAddress.getByName("localhost");
while(true) { String str=breader.readLine(); if(str==null || str.equals("End")) break; buffer=str.getBytes();
ds.send(new DatagramPacket(buffer, str.length(), inet,clientport)); //sends the packet on open client port } } }
|
| Author: din | Member Level: Bronze | Revenue Score:   |
yeah good one....but we cant choose this as final year projects for students this is a small application
|
| Author: Bharath | Member Level: Gold | Revenue Score:   |
You can use it if you want to, but you have to make further modifications to this. Develop it, make it better.
All the best, Study well dude .
|
| Author: vimal gupta | Member Level: Bronze | Revenue Score:   |
You can use it if you want to, but you have to make further modifications to this. Develop it, make it better.
All the best, Study well dude .
|
| Author: vimal gupta | Member Level: Bronze | Revenue Score:   |
yeah good one....but we cant choose this as final year projects for students this is a small application
|