Java program that finds the area of a circle using Client-Server network
Home» Other Circuits» Java program that finds the area of a circle using Client-Server network
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import java.net.*; import java.io.*; public class server { public static void main(String args[]) throws Exception { ServerSocket ss=new ServerSocket(2000); Socket s=ss.accept(); BufferedReader br=new BufferedReader(newInputStreamReader(s.getInputStream())); double rad,area; String result; rad=Double.parseDouble(br.readLine()); System.out.println("From Client : "+rad); area=Math.PI*rad*rad; result="Area is "+area; PrintStream ps=new PrintStream(s.getOutputStream()); ps.println(result); br.close(); ps.close(); s.close(); ss.close(); } } public class client { public static void main(String args[]) throws Exception { Socket s=new Socket("192.168.0.19",2000); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String rad; System.out.println("Enter radius of the circle "); rad=br.readLine(); PrintStream ps=new PrintStream(s.getOutputStream()); ps.println(rad); BufferedReader fs=newBufferedReader(new InputStreamReader(s.getInputStream())); String result=fs.readLine(); System.out.println("From Server : "+result); br.close(); fs.close(); ps.close(); s.close(); } } |
Output:
Java client
Enter radius of the circle
10
From Server: Area is 314.1341345












