-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
32 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
use net_hal::udp::{UdpSocket, UdpServer}; | ||
use addr_hal::SocketAddr; | ||
|
||
use net_hal::udp::{UdpServer, UdpSocket}; | ||
|
||
async fn echo_request<S: UdpSocket>(socket: &mut S) { | ||
match socket.connect(SocketAddr::from(([127, 0, 0, 1], 3400))).await { | ||
match socket | ||
.connect(SocketAddr::from(([127, 0, 0, 1], 3400))) | ||
.await | ||
{ | ||
Ok(s) => s, | ||
Err(_error) => panic!("couldn't connect to address"), | ||
}; | ||
|
||
match socket.send(&[0, 1, 2]).await { | ||
Ok(s) => println!("send buffer size = {}",s), | ||
Ok(s) => println!("send buffer size = {}", s), | ||
Err(_error) => panic!("couldn't send to address"), | ||
}; | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
use net_hal_tokio::udp::TokioUdpSocket; | ||
let mut handle = match TokioUdpSocket::bind(SocketAddr::from(([127, 0, 0, 1], 3401))).await{ | ||
|
||
let mut handle = match TokioUdpSocket::bind(SocketAddr::from(([127, 0, 0, 1], 3401))).await { | ||
Ok(s) => s, | ||
Err(_error) => panic!("couldn't bind to address"), | ||
}; | ||
echo_request(&mut handle).await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
use net_hal::udp::{UdpSocket, UdpServer}; | ||
use addr_hal::SocketAddr; | ||
|
||
use net_hal::udp::{UdpServer, UdpSocket}; | ||
|
||
async fn echo_recv<S: UdpSocket>(socket: &mut S) { | ||
let mut buf = [0;10]; | ||
let _buf_size = match socket.recv(&mut buf).await { | ||
Ok(received) => println!("received {} bytes {:?}", received, &buf[..received]), | ||
Err(_e) => panic!("recv function failed:"), | ||
}; | ||
let mut buf = [0; 10]; | ||
let _buf_size = match socket.recv(&mut buf).await { | ||
Ok(received) => println!("received {} bytes {:?}", received, &buf[..received]), | ||
Err(_e) => panic!("recv function failed:"), | ||
}; | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
use net_hal_tokio::udp::TokioUdpSocket; | ||
let mut handle = match TokioUdpSocket::bind(SocketAddr::from(([127, 0, 0, 1], 3400))).await{ | ||
|
||
let mut handle = match TokioUdpSocket::bind(SocketAddr::from(([127, 0, 0, 1], 3400))).await { | ||
Ok(s) => s, | ||
Err(_error) => panic!("couldn't bind to address"), | ||
}; | ||
echo_recv(&mut handle).await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
use net_hal::udp::{UdpSocket, UdpServer}; | ||
use addr_hal::SocketAddr; | ||
|
||
use net_hal::udp::{UdpServer, UdpSocket}; | ||
|
||
async fn echo_recv<S: UdpSocket>(socket: &mut S) { | ||
let mut buf = [0;10]; | ||
let _buf_size = match socket.recv(&mut buf).await { | ||
Ok(received) => println!("received {} bytes {:?}", received, &buf[..received]), | ||
Err(_e) => panic!("recv function failed:"), | ||
}; | ||
let mut buf = [0; 10]; | ||
let _buf_size = match socket.recv(&mut buf).await { | ||
Ok(received) => println!("received {} bytes {:?}", received, &buf[..received]), | ||
Err(_e) => panic!("recv function failed:"), | ||
}; | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
use net_hal_tokio::udp::TokioUdpSocket; | ||
let mut handle = match TokioUdpSocket::bind(SocketAddr::from(([127, 0, 0, 1], 3400))).await{ | ||
|
||
let mut handle = match TokioUdpSocket::bind(SocketAddr::from(([127, 0, 0, 1], 3400))).await { | ||
Ok(s) => s, | ||
Err(_error) => panic!("couldn't bind to address"), | ||
}; | ||
echo_recv(&mut handle).await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters