-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaytimeServer.java
More file actions
33 lines (29 loc) · 800 Bytes
/
Copy pathDaytimeServer.java
File metadata and controls
33 lines (29 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package Java_Inter;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
public class DaytimeServer {
public final static int PORT = 13;
public static void main(String[] args) {
// TODO Auto-generated method stub
try (ServerSocket server = new ServerSocket(PORT)){
while(true){
try (Socket connection = server.accept()){
System.out.println("已连接");
Writer out = new OutputStreamWriter(connection.getOutputStream());
Date now = new Date();
out.write(now.toString()+"\r\n");
out.flush();
connection.close();
} catch (Exception e) {
// TODO: handle exception
}
}
} catch (Exception e) {
// TODO: handle exception
System.err.println(e);
}
}
}