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
async fn process_socket<T>(_socket: T) {}
#[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
Sourcepub async fn bind<A: ToSocketAddrs>(addr: A) -> Result<Self, Error>
pub async fn bind<A: ToSocketAddrs>(addr: A) -> Result<Self, Error>
Usage is exactly the same as tokio::net::TcpListener::bind
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 Freeze for UdpListener
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