diff --git a/src/lib.rs b/src/lib.rs index fd4bcc2..26d030b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,11 +127,11 @@ pub(crate) const MAX_PKT_BUF_SIZE: usize = 1300; pub(crate) const CONNECTION_TIMEOUT_SEC: i32 = 15; pub(crate) const PACKET_SEND_RATE_SEC: f64 = 1.0 / 10.0; -pub use crate::socket::NetcodeSocket; pub use crate::client::{Client, ClientConfig, ClientState}; pub use crate::crypto::{generate_key, try_generate_key, Key}; pub use crate::error::{Error, Result}; pub use crate::server::{ClientId, ClientIndex, Server, ServerConfig}; +pub use crate::socket::NetcodeSocket; pub use crate::token::{ConnectToken, ConnectTokenBuilder, InvalidTokenError}; pub use crate::transceiver::Transceiver; diff --git a/src/socket.rs b/src/socket.rs index 6e4e522..dd37df1 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -11,7 +11,29 @@ pub struct Error(#[from] std::io::Error); pub type Result = std::result::Result; -pub struct NetcodeSocket(pub UdpSocket); +/// A wrapper around `UdpSocket` that implements the `Transceiver` trait for use in the netcode protocol. +/// +/// `NetcodeSocket` is responsible for creating and managing a UDP socket, handling non-blocking +/// send and receive operations, and providing the local address of the socket. +/// +/// # Note +/// +/// This is a lower-level component and should not be used directly unless you have a specific use case. +/// For most applications, it is recommended to use higher-level abstractions such as `Client::new` or +/// `Client::with_config` to create and manage clients. +/// +/// # Example +/// +/// ``` +/// use netcode::NetcodeSocket; +/// use std::net::SocketAddr; +/// +/// let addr = "127.0.0.1:41235"; +/// let send_buf_size = 256 * 1024; +/// let recv_buf_size = 256 * 1024; +/// let socket = NetcodeSocket::new(addr, send_buf_size, recv_buf_size).unwrap(); +/// ``` +pub struct NetcodeSocket(UdpSocket); impl NetcodeSocket { pub fn new(