1个不稳定版本
0.1.0 | 2024年6月26日 |
---|
#230 in WebSocket
用于swimos
2MB
44K SLoC
SwimOS服务器应用程序
此模块包含SwimOS服务器的主体运行循环。SwimOS服务器包含一个Web服务器,可以使用Warp协议接受传入的WebSocket连接,以与在服务器内运行的代理进行通信。它还将接受针对代理公开的HTTP车道的目标HTTP连接。
通过使用ServerBuilder
来配置服务器应该如何表现来创建服务器实例。默认情况下,服务器不会托管任何代理路由,这些必须通过调用ServerBuilder::add_route
进行注册。仅凭本crate本身不足以生成完整的SwimOS应用程序,因为它不提供代理接口的实现。
由swimos_agent
crate提供代理的Rust实现。
示例
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?;
依赖关系
~21–37MB
~679K SLoC