I am trying to build a simple client server application in which the server should return the working directory.
I am very beginner in Java networking and at the moment I only know how to send a message to the server and display that into the server window. Now I have no idea how can I jump on the next challenging level to print out the server's working directory.
I should use the following example to specify these commands and their responses.
Print the working directory on the server: Client request command:
format (syntax): pwd CRLF
CRLF
where pwd is the keyword to indicate the command; CRLF are characters for carriage return and new line. Only one header line and empty body part in the request message.
meaning(semantics): ask the server to tell the working directory
representation: a line of text string
Server response message:
format (syntax): Status OK CRLF
Lines 1 CRLF
CRLF
working directory path name CRLF that is the response message contains a header line for status, a header for telling number of text lines in the body
meaning(semantics): the current working directory on the server
representation: a line of text string
I already have built an application that looks like this:
    package clients;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ClientSide {
    public static void main(String[] args) {
        try {
            Socket soc=new Socket("localhost",8000);
 PrintStream  ps=new PrintStream(soc.getOutputStream());
            System.out.println("Enter a message to the server: ");
            InputStreamReader isr=new InputStreamReader(System.in);
            BufferedReader br=new BufferedReader(isr);
            String temp=br.readLine();
            ps.println(temp);
       } catch (IOException ex) {
            Logger.getLogger(ClientSide.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
    package serverr;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerrSide {
    public static void main(String[] args) {
        try {
               ServerSocket ss=new ServerSocket(8000);
               Socket s=ss.accept();
               BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
               String receivedData=br.readLine();
               System.out.println("The client says: "+receivedData);
        } catch (Exception e) {
        }
    }
}
