Struct socket_flow::split::WSWriter
source · pub struct WSWriter { /* private fields */ }
Implementations§
source§impl WSWriter
impl WSWriter
pub fn new(writer: Arc<Mutex<Writer>>) -> Self
pub async fn close_connection(&mut self) -> Result<(), Error>
sourcepub async fn send_message(&mut self, message: Message) -> Result<(), Error>
pub async fn send_message(&mut self, message: Message) -> Result<(), Error>
Examples found in repository?
examples/simple_server.rs (line 26)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
async fn main() {
env_logger::init();
let port: u16 = 8080;
match start_server(8080).await {
Ok(mut event_receiver) => {
let mut clients: HashMap<ID, WSWriter> = HashMap::new();
info!("Server started on address 127.0.0.1:{}", port);
while let Some(event) = event_receiver.next().await {
match event {
Event::NewClient(id, client_conn) => {
info!("New client {} connected", id);
clients.insert(id, client_conn);
}
Event::NewMessage(client_id, message) => {
info!("Message from client {}: {:?}", client_id, message);
let ws_writer = clients.get_mut(&client_id).unwrap();
ws_writer.send_message(message).await.unwrap();
}
Event::Disconnect(client_id) => {
info!("Client {} disconnected", client_id);
clients.remove(&client_id);
}
Event::Error(client_id, error) => {
error!("Error occurred for client {}: {:?}", client_id, error);
}
}
}
}
Err(err) => {
eprintln!("Could not start the server due to: {:?}", err);
}
}
}
pub async fn send(&mut self, data: Vec<u8>) -> Result<(), Error>
pub async fn send_as_binary(&mut self, data: Vec<u8>) -> Result<(), Error>
pub async fn send_ping(&mut self) -> Result<(), Error>
pub async fn send_large_data_fragmented( &mut self, data: Vec<u8>, ) -> Result<(), Error>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WSWriter
impl !RefUnwindSafe for WSWriter
impl Send for WSWriter
impl Sync for WSWriter
impl Unpin for WSWriter
impl !UnwindSafe for WSWriter
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)