Skip to main content

RaknetListener

Struct RaknetListener 

Source
pub struct RaknetListener { /* private fields */ }
Expand description

A RakNet UDP server that accepts incoming connections.

Implementations§

Source§

impl RaknetListener

Source

pub async fn bind(sockaddr: &SocketAddr) -> Result<Self>

Bind a RakNet listener to the specified UDP address.

Call listen before accepting connections.

Source

pub async fn from_std(socket: UdpSocket) -> Result<Self>

Creates a listener from a standard UDP socket.

Source

pub async fn listen(&mut self)

Start receiving connection requests.

Call this before accept. Repeated calls have no effect.

Source

pub async fn accept(&mut self) -> Result<RaknetSocket>

Wait for and accept the next incoming RakNet connection.

Call listen first.

§Example
ⓘ
let mut listener = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
listener.listen().await;
let mut socket = listener.accept().await.unwrap();
Source

pub fn get_guid(&self) -> u64

Get the GUID, a random number that uniquely identifies the listener instance.

Source

pub async fn set_motd( &mut self, server_name: &str, max_connection: u32, mc_protocol_version: &str, mc_version: &str, game_type: &str, port: u16, ) -> Result<()>

Set the server-list MOTD returned in unconnected pong packets.

Future ping responses use the updated value.

§Example
ⓘ
let mut listener = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
listener.set_motd("Bedrock Server", 20, "protocol", "version", "Survival", 19132).await?;
Source

pub async fn get_motd(&self) -> String

Return the MOTD sent in unconnected pong packets.

§Example
ⓘ
let listener = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
let motd = listener.get_motd().await;
Source

pub fn local_addr(&self) -> Result<SocketAddr>

Return the local UDP address used by this listener.

§Example
ⓘ
let mut socket = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
assert_eq!(socket.local_addr().unwrap().ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
Source

pub async fn close(&mut self) -> Result<()>

Close the listener and all active connections.

§Example
ⓘ
let mut socket = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
socket.close().await;
Source

pub async fn set_full_motd(&mut self, motd: String) -> Result<()>

Set the full MOTD string used by future unconnected pong responses.

§Example
ⓘ
let mut listener = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
listener.set_full_motd(String::from("motd")).await.unwrap();
Source

pub async fn get_peer_raknet_version(&self, peer: &SocketAddr) -> Result<u8>

Trait Implementations§

Source§

impl Drop for RaknetListener

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V