Actix-web: how to make the client reconnect the websocket server recursivly and asyncly ??

Created on 26 Jan 2020  路  2Comments  路  Source: actix/actix-web

Expected Behavior



Hi!
I want to implement a websocket stress tool acording to and moded from the example of the websocket project under the actix_examples
I expect by setting the client timeout config or a recursivly reconnect founction to improve the success rate of client link server when server busy

Current Behavior

first i set the client config through the

async{
....
let (_,framed)=client::build()
.timeout(Duration::from_secs(15))
.finish()
.ws("htpp://127.0.0.1:8080/ws/")
.connect()
.await
....
}

but when the server got busy the timeout config setting doesn't take effect, after 5s the 408 status was returned
so i try to implement a asyncly reconnect function acording to the async doc
the code like that :

use futures::future::{BoxFuture, FutureExt};

fn recursive(c:&Client ) -> BoxFuture<'static, Framed<BoxedSocket,Codec>> {
    async move {
       let ret0=c.ws(...)
                   .connect()
                   .await;
      match ret0{
            OK((_,framed))=>{framed}
           _=> {
                   delay_for(Duration::from_secs(5)).await;
                  reconnect(c).await
              }
          }
    }.boxed()
}

but the compiler complained a lot of errors such like :

> .boxed()
> ^^^^   `std::rc::Rc<awc::ClientConfig>` cannot be sent between threads safely 

which is quite confusing to me because there are no such type in the context but i guess this must be related with the coroutine yielded value type by the await;
,plaese help me get through of this

Best Regards

Your Environment


hardware: macbook pro 2.6G 6 cores intel i7 16GBRAM 512GB SSD;
op sys: macos mojave 10.14.6;

  • Rust Version (I.e, output of rustc -V): rustc 1.39.0
  • Actix Web Version: Actix web v2.0.0

Most helpful comment

@zhaohansprt .boxed() produces BoxFuture, which contains Send requirement. Try to use .boxed_local().

very nice it works

All 2 comments

@zhaohansprt .boxed() produces BoxFuture, which contains Send requirement. Try to use .boxed_local().

@zhaohansprt .boxed() produces BoxFuture, which contains Send requirement. Try to use .boxed_local().

very nice it works

Was this page helpful?
0 / 5 - 0 ratings