代码如下
struct Ws;
impl Ws{
...
}
impl Actor for Ws {
type Context = ws::WebsocketContext<Self>;
}
impl StreamHandler<Result<Message, ProtocolError>> for Ws {
fn handle(&mut self, msg: Result<Message, ProtocolError>, ctx: &mut Self::Context) {
match msg {
Ok(Message::Ping(msg)) => ctx.pong(&msg),
Ok(Message::Text(text)) => {
let fut = async move {
//调用self.xxx方法
};
let _ = fut.into_actor(self).spawn(ctx);
}
Ok(Message::Close(reason)) => {
ctx.stop();
ctx.close(reason);
}
_ => (),
}
}
}
1
共 1 条评论, 1 页
评论区
写评论可以