Advertisement
sujonshekh

java server clint

Aug 4th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. public class Client_Application {
  2.    
  3.    
  4.     public static void main(String argv[]) throws Exception
  5.  {
  6.      while(true)
  7.      {
  8.         String sentence;
  9.         String modifiedSentence;
  10.         BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
  11.         Socket clientSocket = new Socket("localhost", 6789);
  12.         DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
  13.         BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  14.         sentence = inFromUser.readLine();
  15.         outToServer.writeBytes(sentence + '\n');
  16.         modifiedSentence = inFromServer.readLine();
  17.         System.out.println("FROM SERVER: " + modifiedSentence);
  18.         clientSocket.close();  
  19.      }
  20.  }
  21. }
  22.  
  23. public class Server_Application {
  24.    public static void main(String argv[]) throws Exception
  25.       {
  26.           //System.out.println("This is Server Site");
  27.           Scanner sc= new Scanner(System.in);
  28.          String clientSentence;
  29.          //String capitalizedSentence;
  30.          ServerSocket welcomeSocket = new ServerSocket(6789);
  31.  
  32.          while(true)
  33.          {
  34.             Socket connectionSocket = welcomeSocket.accept();
  35.             BufferedReader inFromClient =
  36.                new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
  37.             DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
  38.             clientSentence = inFromClient.readLine();
  39.             System.out.println("Received: " + clientSentence);
  40.             clientSentence=sc.nextLine();
  41.             //capitalizedSentence = clientSentence.toUpperCase() + '\n';
  42.             outToClient.writeBytes(clientSentence+ '\n');
  43.          }
  44.       }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement