Struct udp_stream::UdpListener
source · pub struct UdpListener { /* private fields */ }
Expand description
An I/O object representing a UDP socket listening for incoming connections.
This object can be converted into a stream of incoming connections for various forms of processing.
§Examples
use udp_stream::UdpListener;
use std::{io, net::SocketAddr, error::Error, str::FromStr};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let mut listener = UdpListener::bind(SocketAddr::from_str("127.0.0.1:8080")?).await?;
loop {
let (socket, _) = listener.accept().await?;
process_socket(socket).await;
}
}
Implementations§
source§impl UdpListener
impl UdpListener
pub async fn bind(local_addr: SocketAddr) -> Result<Self>
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local address that this socket is bound to.
sourcepub async fn accept(&self) -> Result<(UdpStream, SocketAddr)>
pub async fn accept(&self) -> Result<(UdpStream, SocketAddr)>
Accepts a new incoming UDP connection.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for UdpListener
impl Send for UdpListener
impl Sync for UdpListener
impl Unpin for UdpListener
impl !UnwindSafe for UdpListener
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more