-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC10Kclient.java
More file actions
56 lines (44 loc) · 1.56 KB
/
Copy pathC10Kclient.java
File metadata and controls
56 lines (44 loc) · 1.56 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
53
54
55
56
package com.zs.system.io;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.util.LinkedList;
/**
* @author: 马士兵教育
* @create: 2020-06-06 15:12
*/
public class C10Kclient {
public static void main(String[] args) {
LinkedList<SocketChannel> clients = new LinkedList<>();
InetSocketAddress serverAddr = new InetSocketAddress("192.168.150.11", 9090);
//端口号的问题:65535
// windows
for (int i = 10000; i < 65000; i++) {
try {
SocketChannel client1 = SocketChannel.open();
SocketChannel client2 = SocketChannel.open();
/*
linux中你看到的连接就是:
client...port: 10508
client...port: 10508
*/
client1.bind(new InetSocketAddress("192.168.150.1", i));
// 192.168.150.1:10000 192.168.150.11:9090
client1.connect(serverAddr);
clients.add(client1);
client2.bind(new InetSocketAddress("192.168.110.100", i));
// 192.168.110.100:10000 192.168.150.11:9090
client2.connect(serverAddr);
clients.add(client2);
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("clients "+ clients.size());
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
}
}