-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSocket.java
More file actions
52 lines (46 loc) · 1.36 KB
/
Copy pathTestSocket.java
File metadata and controls
52 lines (46 loc) · 1.36 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.caozj.test;
import java.io.IOException;
import com.caozj.framework.util.socket.SocketClientUtil;
import com.caozj.framework.util.socket.SocketServerUtil;
public class TestSocket {
public static void main(String[] args) throws IOException {
final int port = 9876;
new Thread(new Runnable() {
@Override
public void run() {
try {
SocketServerUtil.start(port);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
final int threadCount = 10;
final int count = 10;
final long now = System.currentTimeMillis();
for (int t = 0; t < threadCount; t++) {
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < count; i++) {
// SocketClientUtil.sendAndGetReply("127.0.0.1", port,
// "dasf");
SocketClientUtil.sendContent("127.0.0.1", port, "dasf");
System.out.println("发送socket请求" + i + "次,共耗时:" + (System.currentTimeMillis() - now));
}
}
}).start();
}
// List<String> result = SocketServerUtil.getResp(port);
// for (String content : result) {
// System.out.println("server receive:" + content);
// }
// SocketServerUtil.removeAll(port);
// SocketServerUtil.stop(port);
}
}