Skip to content

Commit

Permalink
document NetcodeSocket (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
benny-n authored Aug 16, 2024
1 parent 85f32b4 commit 0f595e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 23 additions & 1 deletion src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,29 @@ pub struct Error(#[from] std::io::Error);

pub type Result<T> = std::result::Result<T, Error>;

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(
Expand Down

0 comments on commit 0f595e0

Please sign in to comment.