pub struct Conf {
pub host: String,
pub port: u16,
pub socket_conf: SocketConf,
}
Expand description
Main struct used for configuring the connection.
By default, the port number for Java Edition is 25565, and for Bedrock Edition (including Pocket Edition), it is 19132.
Fields§
§host: String
Server IP address or a domain name.
port: u16
Server port.
socket_conf: SocketConf
See SocketConf.
Implementations§
source§impl Conf
impl Conf
sourcepub fn create(host: &str) -> Self
pub fn create(host: &str) -> Self
Create a connection configuration using the default port.
Default port is based on Java Edition(25565), to create a default port based on Bedrock Edition(19132), use Conf::create_with_port to manually specify it.
Examples
let conf = Conf::create("www.example.com");
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() -> Result<(), MspErr> {
let conf = Conf::create("www.example.com");
assert_eq!(conf.host, "www.example.com");
assert_eq!(conf.port, 25565);
assert_eq!(conf.socket_conf, SocketConf::default());
let conf = Conf::create_with_port("www.example.com", 19132);
assert_eq!(conf.port, 19132);
let conf = Conf::create_from_str("192.168.1.10:25565")?;
assert_eq!(conf.host, "192.168.1.10");
assert_eq!(conf.port, 25565);
let conf = Conf::create_from_str("www.example.com:25565")?;
assert_eq!(conf.host, "www.example.com");
assert_eq!(conf.port, 25565);
Ok(())
}
sourcepub fn create_with_port(host: &str, port: u16) -> Self
pub fn create_with_port(host: &str, port: u16) -> Self
Create a connection configuration using the specified port.
Example
let conf = Conf::create_with_port("www.example.com", 19132);
Examples found in repository?
More examples
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() -> Result<(), MspErr> {
let conf = Conf::create("www.example.com");
assert_eq!(conf.host, "www.example.com");
assert_eq!(conf.port, 25565);
assert_eq!(conf.socket_conf, SocketConf::default());
let conf = Conf::create_with_port("www.example.com", 19132);
assert_eq!(conf.port, 19132);
let conf = Conf::create_from_str("192.168.1.10:25565")?;
assert_eq!(conf.host, "192.168.1.10");
assert_eq!(conf.port, 25565);
let conf = Conf::create_from_str("www.example.com:25565")?;
assert_eq!(conf.host, "www.example.com");
assert_eq!(conf.port, 25565);
Ok(())
}
sourcepub fn create_from_str(addr: &str) -> Result<Self, MspErr>
pub fn create_from_str(addr: &str) -> Result<Self, MspErr>
Create a connection configuration by using a string.
Attempting to split the given string into two parts, with the first part being the host of the server and the second part being the port of the server. If the port cannot be converted to u16, it will throw a MspErr error.
Example
let conf = Conf::create_from_str("www.example.com:25565")?;
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() -> Result<(), MspErr> {
let conf = Conf::create("www.example.com");
assert_eq!(conf.host, "www.example.com");
assert_eq!(conf.port, 25565);
assert_eq!(conf.socket_conf, SocketConf::default());
let conf = Conf::create_with_port("www.example.com", 19132);
assert_eq!(conf.port, 19132);
let conf = Conf::create_from_str("192.168.1.10:25565")?;
assert_eq!(conf.host, "192.168.1.10");
assert_eq!(conf.port, 25565);
let conf = Conf::create_from_str("www.example.com:25565")?;
assert_eq!(conf.host, "www.example.com");
assert_eq!(conf.port, 25565);
Ok(())
}
sourcepub fn get_server_status(&self) -> Result<Server, MspErr>
pub fn get_server_status(&self) -> Result<Server, MspErr>
Get info from a modern Java Edition server.
Using the Server List Ping protocol. Suitable for Java Edition servers version 1.7 and above. Return type is Server.
Example
use msp::{Conf, MspErr};
fn main() -> Result<(), MspErr> {
let server = Conf::create("www.example.com");
let info = server.get_bedrock_server_status()?;
Ok(())
}
sourcepub fn get_netty_server_status(&self) -> Result<NettyServer, MspErr>
pub fn get_netty_server_status(&self) -> Result<NettyServer, MspErr>
Get info from a legacy Java Edition server.
This uses a protocol which is compatible with the client-server protocol as it was before the Netty rewrite. Suitable for Java Edition servers version 1.6 and above. Return type is NettyServer.
Example
use msp::{Conf, MspErr};
fn main() -> Result<(), MspErr> {
let server = Conf::create("www.example.com");
let info = server.get_netty_server_status()?;
Ok(())
}
sourcepub fn get_legacy_server_status(&self) -> Result<LegacyServer, MspErr>
pub fn get_legacy_server_status(&self) -> Result<LegacyServer, MspErr>
Get info from a legacy Java Edition server.
Suitable for Java Edition servers version 1.4 to 1.5. Return type is LegacyServer.
Example
use msp::{Conf, MspErr};
fn main() -> Result<(), MspErr> {
let server = Conf::create("www.example.com");
let info = server.get_legacy_server_status()?;
Ok(())
}
sourcepub fn get_beta_legacy_server_status(&self) -> Result<LegacyBetaServer, MspErr>
pub fn get_beta_legacy_server_status(&self) -> Result<LegacyBetaServer, MspErr>
Get info from a beta legacy Java Edition server in beta release.
Suitable for Java Edition servers version beta 1.8 to 1.3. Return type is LegacyBetaServer.
Example
use msp::{Conf, MspErr};
fn main() -> Result<(), MspErr> {
let server = Conf::create("www.example.com");
let info = server.get_beta_legacy_server_status()?;
Ok(())
}
sourcepub fn query(&self) -> Result<QueryBasic, MspErr>
pub fn query(&self) -> Result<QueryBasic, MspErr>
Get basic info from a modern Java Edition server using the Query protocol.
To use this protocol, you need to enable the enable-query option on the server side. See Server Config. Return type is QueryBasic.
Example
use msp::{Conf, MspErr};
fn main() -> Result<(), MspErr> {
let server = Conf::create_with_port("www.example.com", 25565);
let info = server.query()?;
Ok(())
}
sourcepub fn query_full(&self) -> Result<QueryFull, MspErr>
pub fn query_full(&self) -> Result<QueryFull, MspErr>
Get full info from a modern Java Edition server using the Query protocol.
To use this protocol, you need to enable the enable-query option on the server side. See Server Config. Return type is QueryFull.
Example
use msp::{Conf, MspErr};
fn main() -> Result<(), MspErr> {
let server = Conf::create_with_port("www.example.com", 25565);
let info = server.query_full()?;
Ok(())
}
sourcepub fn get_bedrock_server_status(&self) -> Result<BedrockServer, MspErr>
pub fn get_bedrock_server_status(&self) -> Result<BedrockServer, MspErr>
Get info from a modern Bedrock Edition servers using the RakNet protocol
Suitable for Bedrock Edition servers version 1.16.220(protocol 431) and above.
Example
use msp::{Conf, MspErr};
fn main() -> Result<(), MspErr> {
let server = Conf::create_with_port("www.example.com", 19132);
let info = server.get_bedrock_server_status()?;
Ok(())
}
Trait Implementations§
source§impl ToSocketAddrs for Conf
impl ToSocketAddrs for Conf
§type Iter = IntoIter<SocketAddr, Global>
type Iter = IntoIter<SocketAddr, Global>
source§fn to_socket_addrs(&self) -> Result<Self::Iter>
fn to_socket_addrs(&self) -> Result<Self::Iter>
SocketAddr
s. Read more