pub struct WebSocket { /* private fields */ }
Implementations§
Source§impl WebSocket
impl WebSocket
Sourcepub fn new() -> Option<WebSocket>
pub fn new() -> Option<WebSocket>
Create a new WebSocket handler object. One object should be created by socket.
§Examples
let mut ws = WebSocket::new().unwrap();
ws.connect("wss://echo.websocket.org/");
Sourcepub fn connect<T>(&mut self, url: T) -> bool
pub fn connect<T>(&mut self, url: T) -> bool
The connect method open a socket connection to the provided URL. This method should only be call if the current state of the handler is Closed, else the function will do nothing and return false.
§Examples
let mut ws = WebSocket::new().unwrap();
ws.connect("wss://echo.websocket.org/");
Sourcepub fn get_state(&self) -> WebSocketState
pub fn get_state(&self) -> WebSocketState
Get current websocket state.
Sourcepub fn get_buffered_amount(&self) -> usize
pub fn get_buffered_amount(&self) -> usize
Get the WebSocket.bufferedAmount field into bufferedAmount.
Sourcepub fn get_protocol(&self) -> String
pub fn get_protocol(&self) -> String
Get the websocket protocol field.
Sourcepub fn clear_internal_callback(&mut self)
pub fn clear_internal_callback(&mut self)
Clear all internal callbacks for current object.
Sourcepub fn set_open_callback(&mut self, cb: Option<fn(&mut Self)>)
pub fn set_open_callback(&mut self, cb: Option<fn(&mut Self)>)
Set on open callback for current object.
Sourcepub fn set_error_callback(&mut self, cb: Option<fn(&mut Self)>)
pub fn set_error_callback(&mut self, cb: Option<fn(&mut Self)>)
Set on error callback for current object.
Sourcepub fn set_close_callback(&mut self, cb: Option<fn(&mut Self)>)
pub fn set_close_callback(&mut self, cb: Option<fn(&mut Self)>)
Set on close callback for current object.
Sourcepub fn set_message_callback(&mut self, cb: Option<fn(&mut Self, WebSocketData)>)
pub fn set_message_callback(&mut self, cb: Option<fn(&mut Self, WebSocketData)>)
Set on message callback for current object.
Sourcepub fn send_utf8_text<T>(&mut self, string: T) -> bool
pub fn send_utf8_text<T>(&mut self, string: T) -> bool
Send UTF-8 formatted string through websocket. The state of current socket should be opened else the function will return false.
§Examples
let mut ws = WebSocket::new().unwrap();
ws.connect("wss://echo.websocket.org/");
ws.send_utf8_text("foo");
Sourcepub fn send_binary(&mut self, data: &mut [u8]) -> bool
pub fn send_binary(&mut self, data: &mut [u8]) -> bool
Send UTF-8 raw data through websocket. The state of current socket should be opened else the function will return false.
§Examples
let mut ws = WebSocket::new().unwrap();
ws.connect("wss://echo.websocket.org/");
ws.send_binary([42, 69]);