pub struct WebsocketServer { /* private fields */ }Expand description
The WebSocket server itself
Implementations§
Source§impl WebsocketServer
impl WebsocketServer
Sourcepub fn new(
ip_address: String,
port: String,
cert_path: Option<String>,
key_path: Option<String>,
) -> Self
pub fn new( ip_address: String, port: String, cert_path: Option<String>, key_path: Option<String>, ) -> Self
Create a new WebSocket server instance
Sourcepub fn get_message_sender(&self) -> Sender<(String, WebSocketMessage)>
pub fn get_message_sender(&self) -> Sender<(String, WebSocketMessage)>
Get a clone of the message sender for sending messages to clients
Sourcepub fn take_message_receiver(
&self,
) -> Option<Receiver<(String, WebSocketMessage)>>
pub fn take_message_receiver( &self, ) -> Option<Receiver<(String, WebSocketMessage)>>
Take the message receiver to process incoming messages
Sourcepub async fn start(&self) -> Receiver<(String, WebSocketMessage)>
pub async fn start(&self) -> Receiver<(String, WebSocketMessage)>
Start the WebSocket server and return the message receiver for processing incoming messages
Sourcepub async fn send_to_client(
&self,
client_id: String,
message: WebSocketMessage,
) -> Result<(), String>
pub async fn send_to_client( &self, client_id: String, message: WebSocketMessage, ) -> Result<(), String>
Send a message to a specific client
Sourcepub async fn broadcast(&self, message: WebSocketMessage) -> Result<(), String>
pub async fn broadcast(&self, message: WebSocketMessage) -> Result<(), String>
Send a message to all connected clients
Sourcepub async fn get_clients(&self) -> Vec<String>
pub async fn get_clients(&self) -> Vec<String>
Get a list of all connected client IDs
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for WebsocketServer
impl !UnwindSafe for WebsocketServer
impl Freeze for WebsocketServer
impl Send for WebsocketServer
impl Sync for WebsocketServer
impl Unpin for WebsocketServer
impl UnsafeUnpin for WebsocketServer
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