Struct udp_stream::UdpListener
source · [−]pub struct UdpListener { /* private fields */ }
Implementations
sourceimpl UdpListener
impl UdpListener
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};
#[tokio::main]
async fn main() -> io::Result<()> {
let mut listener = UdpListener::bind(SocketAddr::from_str("127.0.0.1:8080").unwrap()).await?;
loop {
let (socket, _) = listener.accept().await?;
process_socket(socket).await;
}
}
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.
pub async fn accept(&self) -> Result<(UdpStream, SocketAddr)>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more