MHSS

Java chat client

Jan 25th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1.  
  2. import java.net.*;
  3. import java.io.*;
  4.  
  5.  
  6. public class  chatclient
  7. {
  8.     public static void main(String args[]) throws Exception
  9.     {
  10.         Socket sk=new Socket("localhost",2000);
  11.         BufferedReader sin=new BufferedReader(new InputStreamReader(sk.getInputStream()));
  12.         PrintStream sout=new PrintStream(sk.getOutputStream());
  13.         BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
  14.         String s;
  15.         while (  true )
  16.         {
  17.             System.out.print("Client : ");
  18.             s=stdin.readLine();
  19.             sout.println(s);
  20.             s=sin.readLine();
  21.             System.out.print("Server : "+s+"\n");
  22.             if ( s.equalsIgnoreCase("BYE") )
  23.                break;
  24.         }
  25.          sk.close();
  26.          sin.close();
  27.          sout.close();
  28.         stdin.close();
  29.     }
  30. }
Add Comment
Please, Sign In to add comment