0% found this document useful (0 votes)
23 views

Write A Java Program That Implements A Simple Client/Server Application

This document provides code for a simple Java client/server application. The client code prompts the user to enter a radius, sends the radius to the server, and receives the calculated area back. The server code accepts the radius from the client, calculates the area of a circle using that radius, and sends the result back to the client.

Uploaded by

Diksha Kashyap
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Write A Java Program That Implements A Simple Client/Server Application

This document provides code for a simple Java client/server application. The client code prompts the user to enter a radius, sends the radius to the server, and receives the calculated area back. The server code accepts the radius from the client, calculates the area of a circle using that radius, and sends the result back to the client.

Uploaded by

Diksha Kashyap
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

WRITE A JAVA PROGRAM THAT IMPLEMENTS A SIMPLE

CLIENT/SERVER APPLICATION.

import java.io.*;
import java.net.*;
class Client
{
public static void main(String ar[])throws Exception
{
Socket s=new Socket(InetAddress.getLocalHost(),10000);
System.out.println("enter the radius of the circle ");
DataInputStream dis=new DataInputStream(System.in);
int n=Integer.parseInt(dis.readLine());
PrintStream ps=new PrintStream(s.getOutputStream());
ps.println(n);
DataInputStream dis1=new DataInputStream(s.getInputStream());
System.out.println("area of the circle from server:"+dis1.readLine());
}
}
import java.io.*;
import java.net.*;
class Server
{
public static void main(String ar[])throws Exception
{
ServerSocket ss=new ServerSocket(10000);
Socket s=ss.accept();
DataInputStream dis=new DataInputStream(s.getInputStream());
int n=Integer.parseInt(dis.readLine());
PrintStream ps=new PrintStream(s.getOutputStream());
ps.println(3.14*n*n);
}
}

OUTPUT

enter the radius of circle : 3

area of the circle from the server: 28.86

You might also like