Crates.io | tdn-bevy |
lib.rs | tdn-bevy |
version | 0.1.2 |
source | src |
created_at | 2024-02-04 08:50:29.262915 |
updated_at | 2024-02-28 04:05:47.700389 |
description | TDN plugin for Bevy game engine. |
homepage | |
repository | https://github.com/cympletech/tdn-bevy |
max_upload_size | |
id | 1126216 |
size | 29,187 |
TDN plugin for Bevy game engine.
tdn-bevy = "0.1.2"
use tdn_bevy::{RecvError, ws::{WsClient, WsClientPlugin, WsConnection}};
fn main() {
App::new()
.add_plugins(WsClientPlugin)
.add_systems(Startup, connect_ws)
.add_systems(Update, receive_message)
.run();
}
fn connect_ws(mut commands: Commands, ws_client: Res<WsClient>) {
ws_client.connect(&mut commands, "127.0.0.1:8000", None);
}
fn receive_message(mut commands: Commands, connections: Query<(Entity, &WsConnection)>) {
for (entity, conn) in connections.iter() {
loop {
match conn.recv() {
Ok(message) => {
println!("message: {}", message);
conn.send(message);
}
Err(RecvError::Empty) => break,
Err(RecvError::Closed) => {
commands.entity(entity).despawn();
break;
}
}
}
}
}
DOING
This project is licensed under either of
at your option.