Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document NetcodeSocket + encapsulate inner UpdSocket #13

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading