#minecraft #ping

craftping

Minecraft Server List Ping Implementation

7 unstable releases

0.4.1 Apr 19, 2023
0.4.0 Mar 21, 2023
0.3.1 Oct 27, 2022
0.3.0 Oct 7, 2021
0.1.0 Mar 23, 2019

#1728 in Network programming

Download history 84/week @ 2023-02-01 29/week @ 2023-02-08 69/week @ 2023-02-15 40/week @ 2023-02-22 68/week @ 2023-03-01 134/week @ 2023-03-08 143/week @ 2023-03-15 49/week @ 2023-03-22 41/week @ 2023-03-29 67/week @ 2023-04-05 26/week @ 2023-04-12 79/week @ 2023-04-19 53/week @ 2023-04-26 78/week @ 2023-05-03 49/week @ 2023-05-10 41/week @ 2023-05-17

227 downloads per month
Used in mc-server-pinger

MIT license

29KB
510 lines

craftping crates.io docs.rs license Actively Maintained

craftping is a Rust library to ping Minecraft Servers.

Usage

[dependencies]
craftping = "0.4.1"

You can synchronously ping to the server with craftping::sync::ping:

use std::net::TcpStream;
use craftping::sync::ping;

fn main() {
    let hostname = "localhost";
    let port = 25565;
    let mut stream = TcpStream::connect((hostname, port)).unwrap();
    let pong = ping(&mut stream, hostname, port).expect("Cannot ping server");
    println!("Ping result: {:?}", pong);
}

sync module requires sync feature, which is enabled by default.

If you want to send pings asynchronously, you can use craftping::tokio::ping or craftping::futures::ping:

  • craftping::tokio::ping
use tokio::net::TcpStream;
use craftping::tokio::ping;

#[tokio::main]
async fn main() {
    let hostname = "localhost";
    let port = 25565;
    let mut stream = TcpStream::connect((hostname, port)).await.unwrap();
    let pong = ping(&mut stream, hostname, port).await.expect("Cannot ping server");
    println!("Ping result: {:?}", pong);
}
  • craftping::futures::ping
use async_std::net::TcpStream;
use craftping::futures::ping;

#[async_std::main]
async fn main() {
    let hostname = "localhost";
    let port = 25565;
    let mut stream = TcpStream::connect((hostname, port)).await.unwrap();
    let pong = ping(&mut stream, hostname, port).await.expect("Cannot ping server");
    println!("Ping result: {:?}", pong);
}

Note that tokio module requires async-tokio feature and futures async-futures.

Check here for more information about ping result.

Contributing

Pull requests are welcome. For major issues, please open the issue on this repository first.

License

MIT

Dependencies

~1–6.5MB
~109K SLoC