Skip to main content

ServerEventHandler

Trait ServerEventHandler 

Source
pub trait ServerEventHandler: Send + Sync {
Show 13 methods // Provided methods fn handle_connect<'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 { ... } fn handle_ping<'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 { ... } fn handle_pong<'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 { ... } fn handle_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 PayloadCommand, 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 { ... } fn handle_event<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 PayloadCommand, 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 { ... } fn handle_ack<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 PayloadCommand, 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 { ... } fn handle_data<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 PayloadCommand, 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 { ... } fn handle_notification_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 NotificationCommand, 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 { ... } fn on_disconnect<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, connection_id: &'life1 str, reason: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn on_error<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, connection_id: &'life1 str, error: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn handle_custom_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 CustomCommand, 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 { ... } 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 handle_system_event<'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 { ... }
}
Expand description

服务端事件处理器

提供细化的命令处理方法,每个命令类型对应一个方法 用户可以实现这个 trait 来自定义业务逻辑

Provided Methods§

Source

fn handle_connect<'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,

处理 CONNECT 系统命令(协商)

默认实现返回 None,表示使用默认处理

Source

fn handle_ping<'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,

处理 PING 系统命令

默认实现返回 None,表示使用默认处理(自动回复 PONG)

Source

fn handle_pong<'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,

处理 PONG 系统命令

默认实现返回 None,表示使用默认处理(更新连接活跃时间)

Source

fn handle_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 PayloadCommand, 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,

处理 MESSAGE 载荷命令(业务消息,需 ACK)

Source

fn handle_event<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 PayloadCommand, 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,

处理 EVENT 载荷命令(事件)

Source

fn handle_ack<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 PayloadCommand, 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,

处理 ACK 载荷命令(确认)

Source

fn handle_data<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 PayloadCommand, 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,

处理 DATA 载荷命令(普通数据传输)

Source

fn handle_notification_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 NotificationCommand, 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,

处理通知命令

§参数
  • command: 通知命令
  • connection_id: 连接 ID
§返回

可选回复 Frame

Source

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

处理连接断开事件

§参数
  • connection_id: 连接 ID
  • reason: 断开原因(如果有)
Source

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

处理连接错误事件

§参数
  • connection_id: 连接 ID
  • error: 错误信息
Source

fn handle_custom_command<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, command: &'life1 CustomCommand, 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,

处理自定义命令

§参数
  • command: 自定义命令
  • connection_id: 连接 ID
§返回

可选回复 Frame

§说明

默认实现返回 None,表示不处理自定义命令 如果需要处理自定义命令,可以重写此方法

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,

处理连接建立完成事件(在 CONNECT 协商完成后调用)

§参数
  • connection_id: 连接 ID
§说明

此方法在 CONNECT 协商完成后调用,用于处理连接建立后的业务逻辑 默认实现为空,如果需要处理连接建立逻辑,可以重写此方法

Source

fn handle_system_event<'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,

处理系统事件(System::Event)

§参数
  • frame: 包含系统事件的 Frame
  • connection_id: 连接 ID
§返回

可选回复 Frame

§说明

默认实现返回 None,表示不处理系统事件 如果需要处理系统事件,可以重写此方法

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§