fork download
  1. package Cau4;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.InputStreamReader;
  6. import java.io.OutputStreamWriter;
  7. import java.io.PrintStream;
  8. import java.net.Socket;
  9.  
  10. public class Client {
  11. private Socket socketOfClient = null;
  12. private BufferedReader in = null;
  13. private BufferedWriter out = null;
  14. private final int PORT = 1995;
  15. private final String HOST_NAME = "localhost";
  16. private static long thoiGianGui;
  17. public void connect() {
  18. try {
  19. socketOfClient = new Socket(HOST_NAME, PORT);
  20.  
  21. // khoi tao luong nhap xuat
  22. socketOfClient.getInputStream()));
  23. socketOfClient.getOutputStream()));
  24. // gui yeu cau cho server cung voi thoi gian gui
  25. out.write("time");
  26. out.newLine();
  27. out.flush();
  28. thoiGianGui = System.currentTimeMillis();
  29. PrintStream ps = new PrintStream(socketOfClient.getOutputStream());
  30. ps.println(thoiGianGui);
  31. // nhan ket qua va hien thi ra:
  32. String result = in.readLine();
  33. System.out.println("Thoi gian he thong la: " + result);
  34. } catch (Exception e) {
  35. // TODO: handle exception
  36. }
  37. }
  38. public static void main(String[] args) {
  39. new Client().connect();
  40. }
  41. }
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:10: error: class Client is public, should be declared in a file named Client.java
public class Client {
       ^
1 error
stdout
Standard output is empty