Struct udp_stream::UdpListener
source · pub struct UdpListener { /* private fields */ }Implementations§
source§impl 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() -> 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;
}
}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§
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