Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

package class_practice;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class fudpserver {

public static void main(String[] args) throws Exception


{
System.out.println("Waiting for client");
DatagramSocket ds = new DatagramSocket(9800);
byte b[] = new byte[100];
DatagramPacket dp= new DatagramPacket(b,100);
ds.receive(dp);
String s= new String(b);

System.out.println(s);
ds.close();
// TODO Auto-generated method stub

}
}

package class_practice;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class fudpclient {

public static void main(String[] args) throws Exception {


DatagramSocket ds = new DatagramSocket();
byte b[] = "This is my UDP client".getBytes();
int len= b.length;
InetAddress ip=
InetAddress.getByName("localhost");
int port_no=9800;
DatagramPacket dp= new
DatagramPacket(b,len,ip,port_no);
ds.send(dp);
ds.close();

// TODO Auto-generated method stub


}

package class_practice;

import java.math.BigInteger;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class fudpclient2 {


public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket();
System.out.println("Enter The Number");
Scanner sc= new Scanner(System.in);
Integer n = sc.nextInt();
BigInteger bigInt = BigInteger.valueOf(n);
byte b[] = bigInt.toByteArray();
int len= b.length;
System.out.println(len);
InetAddress ip=
InetAddress.getByName("localhost");
int port_no=9800;
DatagramPacket dp= new
DatagramPacket(b,len,ip,port_no);
ds.send(dp);
ds.close();

// TODO Auto-generated method stub


}

}
package class_practice;

import java.math.BigInteger;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class fudpserver2 {

public static void main(String[] args) throws Exception


{
System.out.println("Waiting for client");
DatagramSocket ds = new DatagramSocket(9800);
byte b[] = new byte[1];
DatagramPacket dp= new DatagramPacket(b,1);
ds.receive(dp);
int s = new BigInteger(b).intValue();
System.out.println(s);
ds.close();
// TODO Auto-generated method stub

package class_practice;

import java.math.BigInteger;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class fudpserver3 {


public static void main(String[] args) throws Exception
{
System.out.println("Waiting for client");
DatagramSocket ds = new DatagramSocket(9800);
byte b[] = new byte[1];
DatagramPacket dp= new DatagramPacket(b,1);
ds.receive(dp);
int s = new BigInteger(b).intValue();
double a= 3.14*s*s;
System.out.println(a);
ds.close();
// TODO Auto-generated method stub

}
}
package class_practice;

import java.math.BigInteger;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
public class fudpclient3 {
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket();
System.out.println("Enter The Number");
Scanner sc= new Scanner(System.in);
Integer n = sc.nextInt();
BigInteger bigInt = BigInteger.valueOf(n);
byte b[] = bigInt.toByteArray();
int len= b.length;
System.out.println(len);
InetAddress ip=
InetAddress.getByName("localhost");
int port_no=9800;
DatagramPacket dp= new
DatagramPacket(b,len,ip,port_no);
ds.send(dp);
ds.close();

// TODO Auto-generated method stub

}
}

You might also like