Struct reactive_messaging::SocketServer
source · pub struct SocketServer { /* private fields */ }Expand description
The handle to define, start and shutdown a Reactive Server for Socket Connections
Implementations§
source§impl SocketServer
impl SocketServer
sourcepub fn new(interface_ip: String, port: u16) -> Self
pub fn new(interface_ip: String, port: u16) -> Self
Creates a new server instance listening on TCP/IP:
interface_ip: the interface’s IP to listen to – 0.0.0.0 will cause listening to all network interfaces
port: what port to listen to
processor_builder_fn: a function to instantiate a new processor Stream whenever a new connection arrives
sourcepub async fn spawn_responsive_processor<RemotePeerMessages: SocketServerDeserializer<RemotePeerMessages> + Send + Sync + PartialEq + Debug + 'static, LocalPeerMessages: SocketServerSerializer<LocalPeerMessages> + Send + Sync + PartialEq + Debug + 'static, LocalStreamType: Stream<Item = LocalPeerMessages> + Send + 'static, ConnectionEventsCallbackFuture: Future<Output = ()> + Send, ConnectionEventsCallback: Fn(ConnectionEvent<LocalPeerMessages>) -> ConnectionEventsCallbackFuture + Send + Sync + 'static, ProcessorBuilderFn: Fn(String, u16, Arc<Peer<LocalPeerMessages>>, ProcessorRemoteStreamType<RemotePeerMessages>) -> LocalStreamType + Send + Sync + 'static>(
&mut self,
server_events_callback: ConnectionEventsCallback,
dialog_processor_builder_fn: ProcessorBuilderFn
) -> Result<(), Box<dyn Error + Sync + Send + 'static>>
pub async fn spawn_responsive_processor<RemotePeerMessages: SocketServerDeserializer<RemotePeerMessages> + Send + Sync + PartialEq + Debug + 'static, LocalPeerMessages: SocketServerSerializer<LocalPeerMessages> + Send + Sync + PartialEq + Debug + 'static, LocalStreamType: Stream<Item = LocalPeerMessages> + Send + 'static, ConnectionEventsCallbackFuture: Future<Output = ()> + Send, ConnectionEventsCallback: Fn(ConnectionEvent<LocalPeerMessages>) -> ConnectionEventsCallbackFuture + Send + Sync + 'static, ProcessorBuilderFn: Fn(String, u16, Arc<Peer<LocalPeerMessages>>, ProcessorRemoteStreamType<RemotePeerMessages>) -> LocalStreamType + Send + Sync + 'static>( &mut self, server_events_callback: ConnectionEventsCallback, dialog_processor_builder_fn: ProcessorBuilderFn ) -> Result<(), Box<dyn Error + Sync + Send + 'static>>
Spawns a task to run the Server listening @ self’s interface_ip & port and returns, immediately,
an object through which the caller may inquire some stats (if opted in) and request the server to shutdown.
The given dialog_processor_builder_fn will be called for each new client and will return a reactive-mutiny Stream
that will produce non-futures & non-fallibles ServerMessages that will be sent to the clients.
sourcepub fn shutdown_waiter(
&mut self
) -> impl FnOnce() -> BoxFuture<'static, Result<(), Box<dyn Error + Send + Sync>>>
pub fn shutdown_waiter( &mut self ) -> impl FnOnce() -> BoxFuture<'static, Result<(), Box<dyn Error + Send + Sync>>>
Returns an async closure that blocks until [shutdown()] is called. Example:
self.shutdown_waiter()().await;