Skip to main content

ConnectionHandler

Trait ConnectionHandler 

Source
pub trait ConnectionHandler: Send + Sync {
    // Required method
    fn handle_frame<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        frame: &'life1 Frame,
        connection_id: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn on_connect<'life0, 'life1, 'async_trait>(
        &'life0 self,
        connection_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_disconnect<'life0, 'life1, 'async_trait>(
        &'life0 self,
        connection_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

连接处理器

处理单个客户端连接的逻辑

Required Methods§

Source

fn handle_frame<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, frame: &'life1 Frame, connection_id: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

处理接收到的 Frame 消息

§参数
  • frame: 接收到的 Frame
  • connection_id: 连接 ID
§返回

如果需要回复,返回 Some(Frame),否则返回 None

Provided Methods§

Source

fn on_connect<'life0, 'life1, 'async_trait>( &'life0 self, connection_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

处理连接建立事件

§参数
  • connection_id: 连接 ID
Source

fn on_disconnect<'life0, 'life1, 'async_trait>( &'life0 self, connection_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

处理连接断开事件

§参数
  • connection_id: 连接 ID

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ConnectionHandler for ServerMessageWrapper

实现连接处理的接口