Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. package Lab9;
  2.  
  3. import java.io.*;
  4. import java.net.*;
  5.  
  6. public class EchoClient {
  7. public static void main(String[] args) throws IOException {
  8.  
  9. Socket echoSocket = null;
  10. PrintWriter out = null;
  11. BufferedReader in = null;
  12.  
  13. try {
  14. //149.156.207.21
  15. echoSocket = new Socket("localhost", 6666);
  16. out = new PrintWriter(echoSocket.getOutputStream(), true);
  17. in = new BufferedReader(new InputStreamReader(
  18. echoSocket.getInputStream()));
  19. } catch (UnknownHostException e) {
  20. System.err.println("Don't know about host: localhost.");
  21. System.exit(1);
  22. } catch (IOException e) {
  23. System.err.println("Couldn't get I/O for "
  24. + "the connection to: localhost.");
  25. System.exit(1);
  26. }
  27.  
  28. BufferedReader stdIn = new BufferedReader(
  29. new InputStreamReader(System.in));
  30. String userInput;
  31.  
  32. System.out.println("Type a message: ");
  33. while ((userInput = stdIn.readLine()) != null) {
  34. out.println(userInput);
  35. System.out.println("echo: " + in.readLine());
  36. }
  37.  
  38. out.close();
  39. in.close();
  40. stdIn.close();
  41. echoSocket.close();
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement