pub struct Server { /* private fields */ }Expand description
A broadcast relay game server.
Create a server with Server::builder, optionally create rooms with
Server::pre_create_room, then call Server::run to start accepting connections
or use ServerHandle::create_room to perform at runtime, you create a daemon wrapper this way :)
use ghost_sync::Server;
let server = Server::builder()
.bind("0.0.0.0:7777")
.build();
// Spin up the server with an initial rooms (This is not standard, but you have freedom)
server.pre_create_room("standoff").unwrap();
let handle = server.run().await?;
// Rooms can also be managed at runtime via the handle:
// handle.create_room_runtime("match-001").unwrap();Implementations§
Source§impl Server
impl Server
Sourcepub fn builder() -> ServerBuilder
pub fn builder() -> ServerBuilder
Start building a server.
Sourcepub fn pre_create_room(&self, id: &str) -> Result<()>
👎Deprecated: Use ServerHandle::create_room instead, at runtime
pub fn pre_create_room(&self, id: &str) -> Result<()>
Create a room. Call this before Server::run. (pre-run)
Clients can only join rooms that have been explicitly created.
Returns SyncError::RoomAlreadyExists if a room with this ID exists.
Sourcepub fn pre_delete_room(&self, id: &str) -> bool
👎Deprecated: Use ServerHandle::delete_room instead, at runtime
pub fn pre_delete_room(&self, id: &str) -> bool
Delete a room. Call this before Server::run. (pre-run)
Returns true if the room existed.
Sourcepub async fn run(self) -> Result<ServerHandle>
pub async fn run(self) -> Result<ServerHandle>
Start accepting connections.
Binds the TCP listener synchronously. If the bind fails, the error is returned immediately — nothing is spawned on failure.
On success, spawns the accept loop on the current runtime and returns
a ServerHandle for shutdown and runtime control.