Need 1 Page In 3 Hours

profileringringring
Serverprogram3.docx

Server program:-

import java.net.*;

import java.io.*;

class tcpechoserver

{

public static void main(String[] arg) throws IOException

{

ServerSocket s = null;

BufferedReader fromClient = null;

OutputStreamWriter toClient = null;

Socket client = null;

try {

s = new ServerSocket(4000);

System.out.println("Server Ready");

client = s.accept();

System.out.println("Client Connected");

fromClient = new BufferedReader(new InputStreamReader(client.getInputStream()));

toClient = new OutputStreamWriter(client.getOutputStream());

String line;

while (true)

{

line = fromClient.readLine();

if ( (line == null) || line.equals("bye"))

break;

System.out.println ("Client [ " + line + " ]");

toClient.write("Server [ "+ line +" ]\n");

toClient.flush();

}

fromClient.close();

toClient.close();

client.close();

s.close();

System.out.println("Client Disconnected");

}

catch (IOException ioe)

{

System.err.println(ioe);

}

}

}

client program:-

import java.net.*;

import java.io.*;

class myserver

{

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

{

ServerSocket s=new ServerSocket(2020);

System.out.println("Server Waiting....");

Socket so=s.accept();

System.out.println("Connection Established!!");

DataInputStream fromClient=new DataInputStream(so.getInputStream());

DataOutputStream toClient=new DataOutputStream(so.getOutputStream());

while(true)

{

double r=fromClient.readDouble();

double area=3.14*r*r;

toClient.writeDouble(area);

}

}

}