Bevy Simplenet
Provides a bi-directional server/client channel implemented over websockets. This crate is suitable for user authentication, talking to a matchmaking service, communicating between micro-services, games that don't have strict latency requirements, etc.
- Client/server channel includes one-shot messages and a request/response API.
- Client message statuses can be tracked.
- Clients automatically work on native and WASM targets.
- Clients can be authenticated by the server (WIP).
- Provides optional server TLS.
Check out the example for a demonstration of how to build a Bevy client using this crate. NOTE: The example is currently broken until bevy_lunex updates to Bevy v0.13.
Check out bevy_simplenet_events for an event-based framework for networking that builds on this crate.
This crate requires nightly rust.
Features
default: includesbevy,client,serverfeaturesbevy: derivesResourceonClientandServerclient: enables clients (native and WASM targets)server: enables servers (native-only targets)tls-rustls: enables TLS for servers viarustlstls-openssl: enables TLS for servers viaOpenSSL
WASM
On WASM targets the client backend will not update while any other tasks are running. You must either build an IO-oriented application that naturally spends a lot of time polling tasks, or manually release the main thread periodically (e.g. with web_sys::Window::set_timeout_with_callback_and_timeout_and_arguments_0()). For Bevy apps the latter happens automatically at the end of every app update/tick (see the bevy::app::ScheduleRunnerPlugin implementation).
Usage notes
- Servers and clients must be created with enfync runtimes. The backend is ezsockets.
- A client's
AuthRequesttype must match the corresponding server'sAuthenticatortype. - Client ids are defined by clients via their
AuthRequestwhen connecting to a server. This means multiple sessions from the same client will have the same session id. Connections will be rejected if an id is already connected. - Client connect messages will be cloned for all reconnect attempts, so they should be treated as static data.
- Server or client messages may fail to send if the underlying connection is broken. Clients can use the signals returned from
Client::send()andClient::request()to track the status of a message. Client request results will always be emitted byClient::next(). Message tracking is not available for servers. - Tracing levels assume the server is trusted and clients are not trusted.
Example
Setup
Common
Define a channel.
;
;
;
;
;
;
Server
Prepare to make servers.
type TestServerEvent = ;
Make a server and insert it into an app.
Client
Prepare to make clients.
type TestClientEvent = ;
Make a client and insert it into an app.
Sending from the client
Send a message.
Send a request.
Sending from the Server
Send a message.
Send a response.
Reading on the client
Reading on the server
TODOs
- Fix linker errors when the
bevy/dynamic_linkingfeature is enabled. - Implement
AuthTokenfor client/server authentication. - Add server shut down procedure.
- Use const generics to bake protocol versions into
ServerandClientdirectly, instead of relying on factories (currently blocked by lack of robust compiler support). - Move to stable rust once
HashMap::extract_if()is stabilized.
Bevy compatability
| bevy | bevy_simplenet |
|---|---|
| 0.13 | v0.9.0 - master |
| 0.12 | v0.5.0 - v0.8.0 |
| 0.11 | v0 - v0.4.0 |