Hi,all .How would i make client/server app,to calculate surface area of the cylider.
The server must read the cylinders radius and length from the client and calculate the surface area of a cylinder. The server will then return a double representing the surface area of a cylinder to the client. The client must then display the surface area (formatted to two decimal places) to the user
this is my client :

package clientserverapp;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import javax.swing.JOptionPane;


public class Client {


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

     Client  clientSocket = new Client();
     clientSocket.run();

    }



    public void run()throws Exception {
      Socket SOCK = new Socket("localhost", 444);
        PrintStream PS = new PrintStream(SOCK.getOutputStream());
          double p =3.14;

                String radiusInput = JOptionPane.showInputDialog("Enter Radius");
                double r = Double.parseDouble(radiusInput);

                 String heightInput = JOptionPane.showInputDialog("Enter Height");
                 double h = Double.parseDouble(heightInput);

             double surface = (2.0 * r * p * h) + (2.0 * p * r * r);
 JOptionPane.showMessageDialog(null, surface);

        PS.println("Calculating...");

        InputStreamReader IR = new InputStreamReader(SOCK.getInputStream());
        BufferedReader BR = new BufferedReader(IR); 
        String message = BR.readLine();
        System.out.println(message);

    }
}

And here server :

package clientserverapp;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;


public class Server {


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

        Server aServer = new Server();
        aServer.run();
    }

    public void run() throws Exception{

        ServerSocket servSocket = new ServerSocket(444);
        Socket socket = servSocket.accept();

        InputStreamReader IR = new InputStreamReader(socket.getInputStream());
        BufferedReader BR = new BufferedReader(IR);
        String message =  BR.readLine();
        System.out.println(message);

        if(message!=null)
        {
            PrintStream PS  = new PrintStream(socket.getOutputStream());
            Client c = new Client();
            c.run();
            PS.println("Message received");
        }

    }

}

You are nearly there.

In the client, do not calculate the surface. Send the radius and the height to the server. Wait for the reply and extract the area from that.

In the server, extract the radius and height from the received message. Calculate the area. Send the area back to the client in a new message.

Could you give a hint how to send it to the server?Thanks

It's exactly the same as how the server sends a message to the client.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.