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 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)));
sourcepub async fn close(&mut self) -> Result<(), RaknetError>
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;
sourcepub fn set_full_motd(&mut self, motd: String) -> Result<(), RaknetError>
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;