Giter VIP home page Giter VIP logo

actix-sockets's People

Contributors

antholeole avatar sno2 avatar tadeohepperle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

actix-sockets's Issues

Duplicate call of self.lobby_addr.do_send(Disconnect { id: self.id, room_id: self.room });

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

lifetime issue on started method for Ws

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

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);
}

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.