Skip to content

Commit e6fe574

Browse files
committed
更正linux下ipv4与ipv6同时绑定的冲突
1 parent 4f7b8cc commit e6fe574

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

dsserver/src/server.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,23 @@ pub fn run(port: u16, pwd: String) {
2525
(pk >> (1 * 8)) as u8,
2626
pk as u8,
2727
];
28-
let (tx4, rx) = channel::<TcpStream>();
29-
let tx6 = tx4.clone();
30-
std::thread::spawn(move || {
31-
let listener_ipv4 = TcpListener::bind(format!("0.0.0.0:{}", port)).unwrap();
32-
for sr in listener_ipv4.incoming() {
33-
match sr {
34-
Ok(stream) => {
35-
tx4.send(stream).unwrap();
36-
}
37-
Err(e) => {
38-
println!("error {}", e);
28+
let (tx6, rx) = channel::<TcpStream>();
29+
if cfg!(target_os = "windows") {
30+
let tx4 = tx6.clone();
31+
std::thread::spawn(move || {
32+
let listener_ipv4 = TcpListener::bind(format!("0.0.0.0:{}", port)).unwrap();
33+
for sr in listener_ipv4.incoming() {
34+
match sr {
35+
Ok(stream) => {
36+
tx4.send(stream).unwrap();
37+
}
38+
Err(e) => {
39+
println!("error {}", e);
40+
}
3941
}
4042
}
41-
}
42-
});
43+
});
44+
}
4345
std::thread::spawn(move || {
4446
let listener_ipv6 = TcpListener::bind(format!("[::0]:{}", port)).unwrap();
4547
for sr in listener_ipv6.incoming() {

0 commit comments

Comments
 (0)