Struct RaknetListener

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

Implementation of Raknet Server.

Implementations§

Source§

impl RaknetListener

Source

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

Creates a new RaknetListener which will be bound to the specified address.

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

pub async fn from_std(s: UdpSocket) -> Result<Self, RaknetError>

Creates a new RaknetListener from a UdpSocket.

§Example
let raw_socket = std::net::UdpSocket::bind("127.0.0.1:19132").unwrap();
let listener = RaknetListener::from_std(raw_socket);
Source

pub async fn listen(&mut self)

Listen to a RaknetListener

This method must be called before calling RaknetListener::accept()

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

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

Waiting for and receiving new Raknet connections, returning a Raknet socket

Call this method must be after calling RaknetListener::listen()

§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 async fn set_motd( &mut self, server_name: &str, max_connection: u32, mc_protocol_version: &str, mc_version: &str, game_type: &str, port: u16, )

Set the current motd, this motd will be provided to the client in the unconnected pong.

Call this method must be after calling RaknetListener::listen()

§Example
let mut listener = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
listener.set_motd("Another Minecraft Server" , 999999 , "486" , "1.18.11", "Survival" , 19132).await;
Source

pub async fn get_motd(&self) -> String

Get the current motd, this motd will be provided to the client in the unconnected pong.

§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, RaknetError>

Returns the socket address of the local half of this Raknet connection.

§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<(), RaknetError>

Close Raknet Server and all connections.

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

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

Set full motd string.

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

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

Trait Implementations§

Source§

impl Drop for RaknetListener

Source§

fn drop(&mut self)

Executes the destructor for this type. 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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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