fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5. import java.net.Socket;
  6.  
  7. public class Client {
  8. private String host;
  9. private int port;
  10. private Socket connection;
  11. private BufferedReader in;
  12. private PrintWriter out;
  13. private String line;
  14.  
  15. public Client(String host, int port) throws IOException {
  16. this.host = host;
  17. this.port = port;
  18. connection = new Socket(host, port);
  19.  
  20. // stdIn = new BufferedReader(new InputStreamReader(System.in));
  21. }
  22.  
  23. public void send(String input) throws IOException {
  24. out = new PrintWriter(connection.getOutputStream(), true);
  25. out.println(input);
  26. }
  27.  
  28. public String receive() throws IOException {
  29. return "server: " + in.readLine();
  30. }
  31.  
  32. public String receiveAll() throws IOException {
  33. in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  34. StringBuilder result = new StringBuilder();
  35. line = in.readLine();
  36. while (line != null) {
  37. result.append(line + String.format("%n"));
  38. System.out.println("Inside: " + line);
  39. line = in.readLine();
  40. }
  41. return result.toString();
  42. }
  43.  
  44. public void close() throws IOException {
  45. out.close();
  46. in.close();
  47. connection.close();
  48. }
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:7: error: class Client is public, should be declared in a file named Client.java
public class Client {
       ^
1 error
stdout
Standard output is empty