You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
async-std/src/net/mod.rs

36 lines
908 B
Rust

//! Networking primitives for TCP/UDP communication.
//!
//! For OS-specific networking primitives like Unix domain sockets, refer to the [`async_std::os`]
//! module.
//!
//! This module is an async version of [`std::net`].
//!
//! [`async_std::os`]: ../os/index.html
//! [`std::net`]: https://doc.rust-lang.org/std/net/index.html
//!
//! ## Examples
//!
//! A simple UDP echo server:
//!
//! ```no_run
//! # #![feature(async_await)]
//! use async_std::net::UdpSocket;
//!
//! # futures::executor::block_on(async {
//! let socket = UdpSocket::bind("127.0.0.1:8080").await?;
//! let mut buf = vec![0u8; 1024];
//! loop {
//! let (n, peer) = socket.recv_from(&mut buf).await?;
//! socket.send_to(&buf[..n], &peer).await?;
//! }
//! # std::io::Result::Ok(())
//! # }).unwrap();
//! ```
pub use tcp::{Incoming, TcpListener, TcpStream};
pub use udp::UdpSocket;
pub(crate) mod driver;
mod tcp;
mod udp;