8 releases (4 breaking)

0.5.0 Jan 23, 2024
0.4.1 Apr 19, 2023
0.4.0 Mar 21, 2023
0.3.1 Oct 27, 2022
0.1.0 Mar 23, 2019

#2069 in Network programming

Download history 20/week @ 2024-06-29 15/week @ 2024-07-20 30/week @ 2024-07-27 5/week @ 2024-08-03 3/week @ 2024-08-10 6/week @ 2024-08-31 19/week @ 2024-09-07 11/week @ 2024-09-14 54/week @ 2024-09-21 49/week @ 2024-09-28 16/week @ 2024-10-05 45/week @ 2024-10-12

165 downloads per month
Used in mc-server-pinger

MIT license

30KB
529 lines

craftping crates.io docs.rs license Actively Maintained

craftping is a Rust library to ping Minecraft Servers.

Usage

[dependencies]
craftping = "0.5.0"

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–7.5MB
~60K SLoC