forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOClient.java
More file actions
31 lines (28 loc) · 796 Bytes
/
IOClient.java
File metadata and controls
31 lines (28 loc) · 796 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
package JavaDemo.IOTest;
import java.io.IOException;
import java.net.Socket;
import java.util.Date;
/**
* @Classname IOClient
* @Description 客户端
* @Date 19-7-7 下午2:50
* @Created by mao<tianmao818@qq.com>
*/
public class IOClient {
public static void main(String[] args) {
// 开启一个线程
new Thread(() -> {
try {
Socket socket = new Socket("127.0.0.1", 3333);
while (true) {
try {
socket.getOutputStream().write((new Date() + ": hello world").getBytes());
Thread.sleep(2000);
} catch (Exception e) {
}
}
} catch (IOException e) {
}
}).start();
}
}