Advertisement
Guest User

Client.java

a guest
Feb 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.net.*;
  4.  
  5. public class Client implements Runnable{
  6. static Scanner sc;
  7. static PrintWriter p;
  8. static Socket sock;
  9.  
  10. public static void main(String [] args){
  11. try{
  12. sock = new Socket("localhost", 1111);
  13. sc = new Scanner(sock.getInputStream());
  14. p = new PrintWriter(sock.getOutputStream(),true);
  15.  
  16.  
  17. }catch (Exception ex){
  18. ex.printStackTrace();
  19. }
  20. }
  21. @Override
  22. public void run (){
  23. String message;
  24.  
  25. Scanner scan = new Scanner (System.in);
  26. try{
  27. System.out.println(sc.nextLine());
  28. do{
  29. System.out.print("Enter a message: ");
  30. message = scan.nextLine();
  31. p.println(message);
  32. System.out.println(scan.nextLine());
  33. }while(!message.equalsIgnoreCase("quit"));
  34. sock.close();
  35. p.close();
  36. sc.close();
  37. }catch (Exception exb){
  38. exb.printStackTrace();
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement