| Crates.io | bevy_hookup_messenger_websocket |
| lib.rs | bevy_hookup_messenger_websocket |
| version | 2.5.2 |
| created_at | 2025-09-07 14:25:10.441805+00 |
| updated_at | 2025-12-16 14:14:05.455268+00 |
| description | The websocket messenger of the bevy_hookup library |
| homepage | |
| repository | https://github.com/Schoggi0815/bevy_hookup |
| max_upload_size | |
| id | 1828177 |
| size | 162,426 |
A session implementation that works over a websocket channel. This includes both the listener and client for the websocket.
You will need to use tokio and make the main method of your app async.
All you need to do is register the WebsocketServerPlugin::<Sendables> plugin and add an entity with the WebsocketServer::<Sendables> component.
You can add the resource anytime, this will crate the listener for clients to connect to.
Every connected client will get its own Session registered.
#[tokio::main]
async fn main() {
App::new()
.add_plugins((
// Other plugins...
WebsocketServerPlugin::<Sendables>::default(),
))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(WebsocketServer::<Sendables>::new(
// use ip with port here
"0.0.0.0:1234".to_string(),
));
}
This setup is very similar to the server, you just need to register the WebsocketClientPlugin::<Sendables> plugin and add an entity with the WebsocketClient::<Sendables> component.
The resource can of course be added later on, as soon as you create it, it will try to connect to the server using the specified address and port. As soon as a connection is established, the corresponding Session is created.
#[tokio::main]
async fn main() {
App::new()
.add_plugins((
// Other plugins...
WebsocketClientPlugin::<Sendables>::default(),
))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(WebsocketClient::<Sendables>::new(
// use ip with port here
"ws://123.123.123.123:1234".to_string(),
));
}