pub struct WsServer { /* private fields */ }Expand description
WebSocket server adapter that accepts inbound connections.
Listens on a TCP port and spawns a WsConn actor for each incoming
WebSocket connection. Optionally serves a web UI on port + 1 for
peer ID discovery.
Implementations§
Source§impl WsServer
impl WsServer
Sourcepub fn new_with_config(config: Config, ws_config: WsServerConfig) -> Self
pub fn new_with_config(config: Config, ws_config: WsServerConfig) -> Self
Creates a new WebSocket server with custom config.
§Arguments
config- Node configurationws_config- WebSocket server config (port, TLS)
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Returns the current number of connected WebSocket peers.
Test-only helper to poll mesh readiness without relying on
blind sleeps. The count reflects the number of WsConn
actors that have completed the WebSocket handshake and
registered themselves in the server’s client set.
§Use
ⓘ
// Wait for both peers to connect before broadcasting a Put.
while ws_server.peer_count() < 2 {
sleep(Duration::from_millis(50)).await;
}Trait Implementations§
Source§impl Actor for WsServer
impl Actor for WsServer
Source§fn subscribe_to_everything(&self) -> bool
fn subscribe_to_everything(&self) -> bool
WsServer is a relay adapter — it fans out Puts to all connected
WebSocket clients. Must return true so the Router adds it to
server_peers and relays Put messages through it.
Source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 mut self,
msg: Message,
_ctx: &'life1 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>(
&'life0 mut self,
msg: Message,
_ctx: &'life1 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Handle an incoming message.
Source§fn pre_start<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn pre_start<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ctx: &'life1 ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called once before the actor starts processing messages. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for WsServer
impl !UnwindSafe for WsServer
impl Freeze for WsServer
impl Send for WsServer
impl Sync for WsServer
impl Unpin for WsServer
impl UnsafeUnpin for WsServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more