37 lines
940 B
Rust
37 lines
940 B
Rust
use std::net::{Ipv4Addr, SocketAddr};
|
|
use std::time::Duration;
|
|
use bincode::config;
|
|
use color_eyre::eyre::Result;
|
|
use qp2p::{Config, Endpoint};
|
|
use tokio::runtime::Runtime;
|
|
|
|
pub fn main() {
|
|
let runtime = Runtime::new().unwrap();
|
|
|
|
runtime.block_on(async {
|
|
testing_connection().await.unwrap();
|
|
});
|
|
}
|
|
|
|
async fn testing_connection() -> Result<()> {
|
|
color_eyre::install()?;
|
|
|
|
let (node, mut incoming_cx, _contacs) = Endpoint::new_peer(
|
|
SocketAddr::from((Ipv4Addr::LOCALHOST, 3030)),
|
|
&[],
|
|
Config {
|
|
idle_timeout: Duration::from_secs(600000).into(),
|
|
..Default::default()
|
|
},
|
|
)
|
|
.await?;
|
|
|
|
while let Some((connection, mut incoming_connection)) = incoming_cx.next().await {
|
|
loop {
|
|
let bytes = bincode::encode_to_vec("hello world!", config::standard())?;
|
|
connection.send(bytes.into()).await?;
|
|
}
|
|
};
|
|
|
|
Ok(())
|
|
} |