27 lines
775 B
Rust
27 lines
775 B
Rust
use std::thread;
|
|
use std::time::Duration;
|
|
use std::net::SocketAddr;
|
|
use socket2::{Socket, Domain, Type};
|
|
|
|
fn main() {
|
|
loop {
|
|
// create a TCP listener bound to two addresses
|
|
let socket = Socket::new(Domain::ipv6(), Type::stream(), None).unwrap();
|
|
|
|
socket.bind(&"[::1]:12345".parse::<SocketAddr>().unwrap().into()).unwrap();
|
|
// socket.set_only_v6(false).unwrap();
|
|
socket.listen(128).unwrap();
|
|
|
|
let listener = socket.into_tcp_listener();
|
|
println!("Listening ...");
|
|
let (tcp_stream, socket_address) = listener.accept().unwrap();
|
|
|
|
println!("{:?}", socket_address);
|
|
println!("{:?}", tcp_stream);
|
|
|
|
drop(listener);
|
|
println!("Sleeping ...");
|
|
thread::sleep(Duration::from_secs(10));
|
|
}
|
|
}
|