简体   繁体   English

在进行 websocket 调用时,即使在时间用完之前,连接也会超时并显示错误代码 110

[英]Connection times out with error code 110 even before the time runs out while making a websocket call

I want to make a WebSocket call in Rust but the code is throwing a TransportError:我想在 Rust 中进行 WebSocket 调用,但代码抛出了 TransportError:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Transport(Error when opening the TCP socket: Connection timed out (os error 110))', src/main.rs:20:10

I checked my Vultr instance, it does not have a firewall enabled.我检查了我的 Vultr 实例,它没有启用防火墙。

My code sets a connection timeout:我的代码设置了连接超时:

use jsonrpsee_ws_client::WsClientBuilder;
use std::time::Duration;
use subxt::ClientBuilder;

#[subxt::subxt(runtime_metadata_path = "polkadot_metadata.scale")]
pub mod polkadot {}

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();
    // let connection_timeout_secs = Duration::new(secs: 60, nanos: 0);
    let connection_timeout_duration = Duration::new(600, 0);

    let url = "wss://moonriver.api.onfinality.io:9944/public-ws";

    let client = WsClientBuilder::default()
        .connection_timeout(connection_timeout_duration)
        .build(url)
        .await
        .unwrap();

    let api = ClientBuilder::new()
        .set_client(client)
        // .set_url("wss://pub.elara.patract.io:9944/statemine")
        .build()
        .await?
        .to_runtime_api::<polkadot::RuntimeApi<polkadot::DefaultConfig>>();

    let mut iter = api.storage().system().account_iter(None).await?;

    while let Some((key, account)) = iter.next().await? {
        println!("{}: {}", hex::encode(key), account.data.free);
    }
    Ok(())
}

I set a timer and instead of 10 minutes, the error was thrown in 6-7 minutes.我设置了一个计时器,而不是 10 分钟,错误是在 6-7 分钟内引发的。 This makes me think that it is not an actual timeout error but something else, like network settings.这让我认为这不是一个实际的超时错误,而是其他的,比如网络设置。 But I ensured there is no firewall enabled from the Vultr UI .但我确保Vultr UI没有启用防火墙。

It should be port 443 .它应该是端口443
You can debug stuff like this with wscat , I highly recommend it.你可以用wscat调试这样的东西,我强烈推荐它。

wscat -c wss://moonriver.api.onfinality.io:443/public-ws wscat -c wss://moonriver.api.onfinality.io:443/public-ws

You probably saw this, but for everyone else: a simple example to check the connection can be found in the subxt examples .您可能已经看到了这一点,但对其他人来说:可以在subxt 示例中找到一个检查连接的简单示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM