fork download
  1. package Cau4;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStreamWriter;
  8. import java.net.Socket;
  9. import java.util.Calendar;
  10.  
  11. public class ServerThread extends Thread {
  12. private Socket socket = null;
  13. private BufferedReader in = null;
  14. private BufferedWriter out = null;
  15. private long thoiGianNhan;
  16. public ServerThread(Socket socket) {
  17. this.socket = socket;
  18. }
  19.  
  20. @Override
  21. public void run() {
  22. // khoi tao luong vao ra
  23. try {
  24. socket.getInputStream()));
  25. socket.getOutputStream()));
  26.  
  27. // nhan yeu cau tu client
  28. String request = in.readLine();
  29. thoiGianNhan = System.currentTimeMillis();
  30. String result;
  31. if (request.equals("time")) {
  32. Calendar cal = Calendar.getInstance();
  33. result = cal.get(Calendar.HOUR) + ":"
  34. + cal.get(Calendar.MINUTE) + ":"
  35. + cal.get(Calendar.SECOND);
  36. } else {
  37. result = "";
  38. }
  39. // nhan thoi gian ma client gui goi tin di
  40. long thoiGianClientGui = Long.parseLong(in.readLine());
  41. long doTreGoiTin = thoiGianNhan - thoiGianClientGui;
  42. // tra ve ket qua cho client
  43. out.write(result + " Do tre la " + doTreGoiTin);
  44. out.newLine();
  45. out.flush();
  46.  
  47. } catch (IOException e) {
  48. // TODO Auto-generated catch block
  49. e.printStackTrace();
  50. }
  51. }
  52. }
  53.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:11: error: class ServerThread is public, should be declared in a file named ServerThread.java
public class ServerThread extends Thread {
       ^
1 error
stdout
Standard output is empty