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<IntoString: Into<String>>(
interface_ip: IntoString,
port: u16
) -> Self
pub fn new<IntoString: Into<String>>( interface_ip: IntoString, 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<ClientMessages: ReactiveMessagingDeserializer<ClientMessages> + Send + Sync + PartialEq + Debug + 'static, ServerMessages: ReactiveMessagingSerializer<ServerMessages> + ResponsiveMessages<ServerMessages> + Send + Sync + PartialEq + Debug + 'static, ServerStreamType: Stream<Item = ServerMessages> + Send + 'static, ConnectionEventsCallbackFuture: Future<Output = ()> + Send, ConnectionEventsCallback: Fn(ConnectionEvent<ServerMessages>) -> ConnectionEventsCallbackFuture + Send + Sync + 'static, ProcessorBuilderFn: Fn(String, u16, Arc<Peer<ServerMessages>>, ProcessorRemoteStreamType<ClientMessages>) -> ServerStreamType + Send + Sync + 'static>(
&mut self,
connection_events_callback: ConnectionEventsCallback,
dialog_processor_builder_fn: ProcessorBuilderFn
) -> Result<(), Box<dyn Error + Sync + Send + 'static>>
pub async fn spawn_responsive_processor<ClientMessages: ReactiveMessagingDeserializer<ClientMessages> + Send + Sync + PartialEq + Debug + 'static, ServerMessages: ReactiveMessagingSerializer<ServerMessages> + ResponsiveMessages<ServerMessages> + Send + Sync + PartialEq + Debug + 'static, ServerStreamType: Stream<Item = ServerMessages> + Send + 'static, ConnectionEventsCallbackFuture: Future<Output = ()> + Send, ConnectionEventsCallback: Fn(ConnectionEvent<ServerMessages>) -> ConnectionEventsCallbackFuture + Send + Sync + 'static, ProcessorBuilderFn: Fn(String, u16, Arc<Peer<ServerMessages>>, ProcessorRemoteStreamType<ClientMessages>) -> ServerStreamType + Send + Sync + 'static>( &mut self, connection_events_callback: ConnectionEventsCallback, dialog_processor_builder_fn: ProcessorBuilderFn ) -> Result<(), Box<dyn Error + Sync + Send + 'static>>
Spawns a task to run a 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 async fn spawn_unresponsive_processor<ClientMessages: ReactiveMessagingDeserializer<ClientMessages> + Send + Sync + PartialEq + Debug + 'static, ServerMessages: ReactiveMessagingSerializer<ServerMessages> + Send + Sync + PartialEq + Debug + 'static, OutputStreamItemsType: Send + Sync + Debug + 'static, ServerStreamType: Stream<Item = OutputStreamItemsType> + Send + 'static, ConnectionEventsCallbackFuture: Future<Output = ()> + Send, ConnectionEventsCallback: Fn(ConnectionEvent<ServerMessages>) -> ConnectionEventsCallbackFuture + Send + Sync + 'static, ProcessorBuilderFn: Fn(String, u16, Arc<Peer<ServerMessages>>, ProcessorRemoteStreamType<ClientMessages>) -> ServerStreamType + Send + Sync + 'static>(
&mut self,
connection_events_callback: ConnectionEventsCallback,
dialog_processor_builder_fn: ProcessorBuilderFn
) -> Result<(), Box<dyn Error + Sync + Send + 'static>>
pub async fn spawn_unresponsive_processor<ClientMessages: ReactiveMessagingDeserializer<ClientMessages> + Send + Sync + PartialEq + Debug + 'static, ServerMessages: ReactiveMessagingSerializer<ServerMessages> + Send + Sync + PartialEq + Debug + 'static, OutputStreamItemsType: Send + Sync + Debug + 'static, ServerStreamType: Stream<Item = OutputStreamItemsType> + Send + 'static, ConnectionEventsCallbackFuture: Future<Output = ()> + Send, ConnectionEventsCallback: Fn(ConnectionEvent<ServerMessages>) -> ConnectionEventsCallbackFuture + Send + Sync + 'static, ProcessorBuilderFn: Fn(String, u16, Arc<Peer<ServerMessages>>, ProcessorRemoteStreamType<ClientMessages>) -> ServerStreamType + Send + Sync + 'static>( &mut self, connection_events_callback: ConnectionEventsCallback, dialog_processor_builder_fn: ProcessorBuilderFn ) -> Result<(), Box<dyn Error + Sync + Send + 'static>>
Spawns a task to run a 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 items that won’t be sent to the clients
– if you want the processor to produce “answer messages” to the clients, see SocketServer::spawn_responsive_processor().
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;sourcepub fn shutdown(self, timeout_ms: u32) -> Result<(), Box<dyn Error>>
pub fn shutdown(self, timeout_ms: u32) -> Result<(), Box<dyn Error>>
Notifies the server it is time to shutdown.
The provided connection_events callback will be executed for up to timeout_ms milliseconds
– in which case it is a good practice to inform all the clients that a server-initiated disconnection (due to a shutdown) is happening.