pub struct RaknetSocket { /* private fields */ }
Expand description
Raknet socket wrapper with local and remote.
Implementations§
Source§impl RaknetSocket
impl RaknetSocket
Sourcepub async fn from(
addr: &SocketAddr,
s: &Arc<UdpSocket>,
receiver: Receiver<Vec<u8>>,
mtu: u16,
collecter: Arc<Mutex<Sender<SocketAddr>>>,
raknet_version: u8,
) -> Self
pub async fn from( addr: &SocketAddr, s: &Arc<UdpSocket>, receiver: Receiver<Vec<u8>>, mtu: u16, collecter: Arc<Mutex<Sender<SocketAddr>>>, raknet_version: u8, ) -> Self
Create a Raknet Socket from a UDP socket with an established Raknet connection
This method is used for RaknetListener, users of the library should not care about it.
Sourcepub async fn connect(addr: &SocketAddr) -> Result<Self, RaknetError>
pub async fn connect(addr: &SocketAddr) -> Result<Self, RaknetError>
pub async fn connect_with_version( addr: &SocketAddr, raknet_version: u8, ) -> Result<Self, RaknetError>
Sourcepub async fn close(&self) -> Result<(), RaknetError>
pub async fn close(&self) -> Result<(), RaknetError>
Close Raknet Socket. Normally you don’t need to call this method, the RaknetSocket will be closed automatically when it is released. This method can be called repeatedly.
§Example
ⓘ
let (latency, motd) = socket::RaknetSocket::ping("127.0.0.1:19132".parse().unwrap()).await.unwrap();
assert!((0..10).contains(&latency));
Sourcepub async fn send(&self, buf: &[u8], r: Reliability) -> Result<(), RaknetError>
pub async fn send(&self, buf: &[u8], r: Reliability) -> Result<(), RaknetError>
Send a packet
packet must be 0xfe
as the first byte, using other values of bytes may cause unexpected errors.
Except Reliability::ReliableOrdered, all other reliability packets must be less than MTU - 60 (default 1340 bytes), otherwise RaknetError::PacketSizeExceedMTU will be returned
§Example
ⓘ
let socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap();
socket.send(&[0xfe], Reliability::ReliableOrdered).await.unwrap();
Sourcepub fn peer_addr(&self) -> Result<SocketAddr, RaknetError>
pub fn peer_addr(&self) -> Result<SocketAddr, RaknetError>
Sourcepub fn local_addr(&self) -> Result<SocketAddr, RaknetError>
pub fn local_addr(&self) -> Result<SocketAddr, RaknetError>
Sourcepub fn raknet_version(&self) -> Result<u8, RaknetError>
pub fn raknet_version(&self) -> Result<u8, RaknetError>
return the raknet version used by this connection.
Sourcepub fn set_loss_rate(&mut self, stage: u8)
pub fn set_loss_rate(&mut self, stage: u8)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RaknetSocket
impl !RefUnwindSafe for RaknetSocket
impl Send for RaknetSocket
impl Sync for RaknetSocket
impl Unpin for RaknetSocket
impl !UnwindSafe for RaknetSocket
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