1 unstable release

0.1.0 Jun 26, 2024

#154 in WebSocket


Used in swimos

Apache-2.0

2MB
44K SLoC

SwimOS Server Application

This module contains the main runtime loop for the SwimOS server. A SwimOS server contains a web server that can accept incoming websocket connections, using the Warp protocol, to communicate with agents that run within the server. It will additionally accept plain HTTP connections that are targetted at HTTP lanes exposed by the agents.

A server instance is created by using the ServerBuilder to configure how the server should behave. By default, a server will not host any agent routes and these must be registered by calling ServerBuilder::add_route. This crate is not sufficient, in itself, to produce a complete SwimOS application as it does not supply any implementation of the agent interface.

A Rust implementation of agents is provided by the swimos_agent crate.

Examples

use std::error::Error;
use swimos_server_app::{Server, ServerBuilder};

let server = ServerBuilder::with_plane_name("Example Server")
    .set_bind_addr("127.0.0.1:8080".parse()?)
    .enable_introspection()
    .with_in_memory_store()
    // Register agent routes.
    .build()
    .await?;

let (task, mut handle) = server.run();
let stop = async move {
    ctrl_c.await; // Provide a signal to cause the server to stop. E.g. Ctrl-C.
    handle.stop();
};
tokio::join!(stop, task).1?;

Dependencies

~21–36MB
~678K SLoC