Struct rust_raknet::RaknetListener
source · [−]pub struct RaknetListener { /* private fields */ }
Expand description
Implementation of Raknet Server.
Implementations
sourceimpl RaknetListener
impl RaknetListener
sourcepub async fn bind(sockaddr: &SocketAddr) -> Result<Self, RaknetError>
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();
sourcepub async fn from_std(s: UdpSocket) -> Result<Self, RaknetError>
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);
sourcepub async fn listen(&mut self)
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;
sourcepub async fn accept(&mut self) -> Result<RaknetSocket, RaknetError>
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();
sourcepub async fn set_motd(
&mut self,
server_name: &str,
max_connection: u32,
mc_protocol_version: &str,
mc_version: &str,
game_type: &str,
port: u16
)
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;
sourcepub async fn get_motd(&self) -> String
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 mut listener = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
let motd = listener.get_motd().await;
sourcepub fn local_addr(&self) -> Result<SocketAddr, RaknetError>
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)));
Auto Trait Implementations
impl !RefUnwindSafe for RaknetListener
impl Send for RaknetListener
impl Sync for RaknetListener
impl Unpin for RaknetListener
impl !UnwindSafe for RaknetListener
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more