Advertisement
NB52053

server final

Aug 3rd, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package sa;
  2. import java.net.*;
  3. import java.io.*;
  4.  
  5. public class Server{
  6.  
  7.     public static void main(String[] args) throws IOException {
  8.  
  9.     try{
  10.         ServerSocket  ss=new ServerSocket(5432);
  11.         System.out.println("listening mode");
  12.         Socket s=ss.accept();
  13.  
  14.         System.out.println(("request accepted"));
  15.         BufferedReader read=new BufferedReader(new InputStreamReader(System.in));  // Own console read!
  16.  
  17.         OutputStream os=s.getOutputStream(); // To send to Client!
  18.         InputStream is=s.getInputStream();  // Read From Client!
  19.         PrintWriter pw=new PrintWriter(os);  // To sent to Client!
  20.         BufferedReader RecieveRead= new BufferedReader(new InputStreamReader(is)); // Read from Client!
  21.  
  22.         String RecieveMsg,SendMsg;
  23.        // String input1=.nextLine;
  24.         while (true){
  25.          RecieveMsg=RecieveRead.readLine(); // Client theke read kore //ReceiveMsg  variable e rakhtese!
  26.               System.out.println(RecieveMsg); // Just show krbe arki console e  //ki msg dise.
  27.               if(RecieveMsg==null||RecieveMsg.equals("exit")) // ReceivMsg jodi null hoye jay! mane arr kono kisu jodi client na pathay ba EXIT dey taile //close hye jbe  
  28.                   break;
  29.  
  30.  
  31.             SendMsg=read.readLine(); // Ami console e jaa likhbo seita SendMsg //e joma hcche client ke pathanor jnne!
  32.             System.out.println(SendMsg);
  33.             pw.println(SendMsg);  // Upore PrintWritter er object holo ei pw
  34. // pw ki kore ? mone ache ? jst write kore diye ashe! Client ke pathay dicche //arki send mssg gula amr
  35.             pw.flush(); // ekta msg dile thn flush kore dicche jst
  36.             if(SendMsg==null||SendMsg.equals("exit")) // amio jodi Exit dei //taile close hbe arki
  37.                 break;
  38.  
  39.         }
  40.  
  41.         }
  42.         catch(IOException e)
  43.         {
  44.             e.printStackTrace();
  45.  
  46.         }
  47.  
  48.     }
  49.  
  50.  
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement