Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kiwiyou/craftping
Minecraft Server List Ping in Rust
https://github.com/kiwiyou/craftping
minecraft rust
Last synced: 5 days ago
JSON representation
Minecraft Server List Ping in Rust
- Host: GitHub
- URL: https://github.com/kiwiyou/craftping
- Owner: kiwiyou
- License: mit
- Created: 2019-03-23T10:14:11.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-06-29T12:23:15.000Z (6 months ago)
- Last Synced: 2024-12-16T22:07:52.286Z (12 days ago)
- Topics: minecraft, rust
- Language: Rust
- Homepage:
- Size: 47.9 KB
- Stars: 34
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# craftping [![crates.io](https://img.shields.io/crates/v/craftping.svg)](https://crates.io/crates/craftping) [![docs.rs](https://docs.rs/craftping/badge.svg)](https://docs.rs/craftping) ![license](https://img.shields.io/github/license/kiwiyou/craftping.svg) [![Actively Maintained](https://img.shields.io/badge/Maintenance%20Level-Actively%20Maintained-green.svg)](https://github.com/kiwiyou/craftping)
craftping is a Rust library to ping Minecraft Servers.
## Usage
```toml
[dependencies]
craftping = "0.5.0"
```You can synchronously ping to the server with `craftping::sync::ping`:
```rust
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`
```rust
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`
```rust
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](https://wiki.vg/Server_List_Ping#Response) for more information about ping result.
## Contributing
Pull requests are welcome. For major issues, please open the issue on this repository first.
## License
[MIT](https://choosealicense.com/licenses/mit/)