Trait ws::Handler [] [src]

pub trait Handler {
    fn settings(&mut self) { ... }
    fn on_shutdown(&mut self) { ... }
    fn on_open(&mut self, shake: Handshake) -> Result<()> { ... }
    fn on_message(&mut self, msg: Message) -> Result<()> { ... }
    fn on_close(&mut self, code: CloseCode, reason: &str) { ... }
    fn on_error(&mut self, err: Error) { ... }
    fn on_request(&mut self, req: &Request) -> Result<()> { ... }
    fn on_response(&mut self, res: &Response) -> Result<()> { ... }
    fn on_ping_frame(&mut self, frame: Frame) -> Result<Option<Frame>> { ... }
    fn on_pong_frame(&mut self, frame: Frame) -> Result<Option<Frame>> { ... }
    fn on_close_frame(&mut self, frame: Frame) -> Result<Option<Frame>> { ... }
    fn on_binary_frame(&mut self, frame: Frame) -> Result<Option<Frame>> { ... }
    fn on_text_frame(&mut self, frame: Frame) -> Result<Option<Frame>> { ... }
    fn on_fragmented_frame(&mut self, frame: Frame) -> Result<Option<Frame>> { ... }
}

all of these methods are called when receiving data from another endpoint not when data is sent from this endpoint

Provided Methods

fn settings(&mut self)

fn on_shutdown(&mut self)

fn on_open(&mut self, shake: Handshake) -> Result<()>

fn on_message(&mut self, msg: Message) -> Result<()>

fn on_close(&mut self, code: CloseCode, reason: &str)

fn on_error(&mut self, err: Error)

fn on_request(&mut self, req: &Request) -> Result<()>

return an Error to reject the request

fn on_response(&mut self, res: &Response) -> Result<()>

return an Error to reject the handshake response

fn on_ping_frame(&mut self, frame: Frame) -> Result<Option<Frame>>

return Some(ping) to allow a pong to be sent for you return None to takeover processing the ping, you will need to send a pong yourself

fn on_pong_frame(&mut self, frame: Frame) -> Result<Option<Frame>>

return Some(pong) to pass the pong back, which will mean that default validation may run return None to takeover processing the pong yourself

fn on_close_frame(&mut self, frame: Frame) -> Result<Option<Frame>>

return Some(frame) to pass the close frame back, which will send a closing response frame and trigger on_close. This method is only called when the connection is still open, if the connection is already closing (because you sent a close frame or an error occured on your side), this method will not be called return None to takeover processing the close yourself

fn on_binary_frame(&mut self, frame: Frame) -> Result<Option<Frame>>

This method is only called when the message is not fragmented return Some(frame) to pass the frame back and continue processing it into a message return None to takeover processing the frame yourself

fn on_text_frame(&mut self, frame: Frame) -> Result<Option<Frame>>

This method is only called when the message is not fragmented return Ok(frame) to pass the frame back and continue processing it into a message return Ok(None) to takeover processing the frame yourself

fn on_fragmented_frame(&mut self, frame: Frame) -> Result<Option<Frame>>

This method is only called when the message is fragmented, and it should be called with each fragment in order return Ok(frame) to pass the frame back and continue processing it into a message return Ok(None) to takeover processing the frame yourself, if you do this, you must do it for all fragments of the message, otherwise the message will be incomplete when sent to the message handler

Implementors