antholeole / actix-sockets Goto Github PK
View Code? Open in Web Editor NEWA Rust Demo Webapp for showing how to use websockets in actix web.
A Rust Demo Webapp for showing how to use websockets in actix web.
Hey, I think there is a bug in this section of the code:
fn hb(&self, ctx: &mut ws::WebsocketContext<Self>) {
ctx.run_interval(HEARTBEAT_INTERVAL, |act, ctx| {
if Instant::now().duration_since(act.hb) > CLIENT_TIMEOUT {
println!("Disconnecting failed heartbeat");
act.lobby_addr.do_send(Disconnect { id: act.id, room_id: act.room });
ctx.stop();
return;
}
ctx.ping(b"PING");
});
}
It is unnecessary to call act.lobby_addr.do_send(Disconnect { id: act.id, room_id: act.room });
here, because the ctx.stop();
will cause the actor to enter the stopping state. In that case the body of the stopping()
function is run, which already sends a Disconnect message:
fn stopping(&mut self, _: &mut Self::Context) -> Running {
self.lobby_addr.do_send(Disconnect { id: self.id, room_id: self.room });
Running::Stop
}
If you give me permissions to make a PR I'll fix it quickly
Since I am trying to use actix websocket to make communication, I found this repo that is really useful!!!
However I just cannot know run it up, for instance how to send a PING and get PONG response (the command like curl -X GET http://127.0.0.1:8080/ws/...) what commands should I use?
Thanks for this neat tutorial ! It helped me to write a websocket service for my project.
I am running into the following issue in the started
method for the WS actor :
impl Actor for WsConn {
type Context = ws::WebsocketContext<Self>;
fn started(&mut self, ctx: &mut Self::Context) {
self.hb(ctx);
let addr = ctx.address();
self.lobby_addr
.send(Connect {
addr: addr.recipient(),
lobby_id: self.room,
self_id: self.id,
})
.into_actor(self)
.then(|res, _, ctx| {
match res {
Ok(_res) => (),
_ => ctx.stop(),
}
fut::ready(())
})
.wait(ctx);
}
It won't build because self
is captured into the then
closure so there is a lifetime issue.
Note that i am using different versions :
actix = { version = "0.12.0"}
actix-web-actors = "=4.0.0-beta.6"
any idea what i am doing wrong ? I've been banging my head the whole day against this
no method named then
found for struct actix::fut::future::FutureWrap
in the current scope
method not found in actix::fut::future::FutureWrap<actix::address::message::MsgRequest<actix::dev::channel::AddressSender<lobby::Lobby>, messages::Connect>, ws::WsConn>
help: items from traits can only be used if the trait is in scoperustc(E0599)
ws.rs(46, 14): method not found in actix::fut::future::FutureWrap<actix::address::message::MsgRequest<actix::dev::channel::AddressSender<lobby::Lobby>, messages::Connect>, ws::WsConn>
mod.rs(142, 8): the method is available for actix::fut::future::FutureWrap<actix::address::message::MsgRequest<actix::dev::channel::AddressSender<lobby::Lobby>, messages::Connect>, ws::WsConn>
here
`
fn started(&mut self, ctx: &mut Self::Context) {
self.hb(ctx);
let addr = ctx.address();
self.lobby_addr
.send(Connect {
addr: addr.recipient(),
lobby_id: self.room,
self_id: self.id,
})
.into_actor(self)
.then(|res, _, ctx| {
match res {
Ok(_res) => (),
_ => ctx.stop(),
}
fut::ready(())
})
.wait(ctx);
}
`
Seems to run in timeout
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.