Advertisement
FahimFaisal

Client

Feb 18th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package SocketProgramming3_ECHO;
  7.  
  8. import java.io.IOException;
  9. import java.net.Socket;
  10. import java.io.*;
  11.  
  12. /**
  13.  *
  14.  * @author acer
  15.  */
  16. public class Client {
  17.    
  18.     private static final String SERVER_IP="localhost";
  19.     private static final int SERVER_PORT=9090;
  20.    
  21.     public static void main(String[] args) throws IOException {
  22.         System.out.println("[Client] Client Started");
  23.         Socket client=new Socket(SERVER_IP,SERVER_PORT);
  24.        
  25.        
  26.         /////////////////getting input from user//////////////////////////////////////////
  27.         System.out.println("[Client]: enter a string ");
  28.         BufferedReader userInput=new BufferedReader(new InputStreamReader(System.in));
  29.         String input=userInput.readLine();
  30.        
  31.         ///////////////////sending request through socket/////////////////////////////
  32.         PrintWriter out=new PrintWriter(client.getOutputStream(),true);
  33.         out.println(input);
  34.        
  35.         ///////////////////Getting reply from socket/////////////////////////////
  36.         BufferedReader ServerReplyInput=new BufferedReader(new InputStreamReader(client.getInputStream()));
  37.         String ServerReply=ServerReplyInput.readLine();
  38.         System.out.println("[Server]"+ServerReply);
  39.         client.close();
  40.        
  41.        
  42.        
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement