10 releases (6 breaking)

Uses new Rust 2024

new 0.7.0 Mar 17, 2025
0.5.0 Jan 23, 2024
0.4.1 Apr 19, 2023
0.4.0 Mar 21, 2023
0.1.0 Mar 23, 2019

#553 in Network programming

Download history 11/week @ 2024-12-01 39/week @ 2024-12-08 32/week @ 2024-12-15 4/week @ 2025-01-05 14/week @ 2025-01-12 7/week @ 2025-01-19 14/week @ 2025-01-26 383/week @ 2025-02-02 49/week @ 2025-02-09 22/week @ 2025-02-16 37/week @ 2025-02-23 29/week @ 2025-03-02 110/week @ 2025-03-09 346/week @ 2025-03-16

525 downloads per month
Used in mc-server-pinger

MIT license

29KB
492 lines

craftping crates.io docs.rs license Actively Maintained

craftping is a Rust library to ping Minecraft Servers.

Usage

[dependencies]
craftping = "0.7.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

~0.9–7.5MB
~58K SLoC