Coder Social home page Coder Social logo

signalr-rs's Introduction

Required

Rust 2018

Cargo Features

  • no_trace_release : disable trace logs in release, useful if there is sensitive information in the URL
  • zstd : zstd compression for actix

defaults : zstd

Purpose

Signalr actor client for actix and rust, using futures 0.3 async/await

bittrex example

There is a bittrex example which provides a basic example of using the actor

signalr-rs's People

Contributors

igosuki avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

signalr-rs's Issues

Issue compiling the library

I'm having issues compiling the library while implementing the signal-rs library into my project.
The library also fails to compile whenever I try to compile it at it's own.

Getting the error:
error[E0554] `#![feature]` may not be used on the stable release channel
 --> /Users/uzaaft/.cargo/registry/src/github.com-1ecc6299db9ec823/signalr_rs-0.1.4/src/lib.rs:1:1
  |
1 | #![feature(try_trait)]
  | ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0554`.
error: could not compile `signalr_rs`

To learn more, run the command again with --verbose.
[Finished running. Exit status: 101]
Attempting to compile it with:

macOS Monterey beta
cargo 1.53.0 (4369396ce 2021-04-27)
rustc 1.53.0 (53cb7b09b 2021-06-17)
Do tell if more information is needed.

JWT authentication support

Is JWT authentication supported? I don't see any way to do this, which the server application I wish to connect to requires. If not, are there any plans to support JWTs?

client.rs error E0432 use std::option::NoneError

I'm unable to compile the signalr-rs crate on either Windows or Linux, using either the stable or nightly build of the rust tooling. I always get this error:

error[E0432]: unresolved import std::option::NoneError
--> /home/iantr/.cargo/registry/src/github.com-1ecc6299db9ec823/signalr_rs-0.1.4/src/hub/client.rs:21:5
|
21 | use std::option::NoneError;
| ^^^^^^^^^^^^^^^^^^^^^^ no NoneError in option

Can't get a basic client to communicate with a SignalR server

I created a basic SignalR server following Microsoft's walkthrough here: https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr

It was trivial to create a C# console client to talk to it. I'm trying to do the same with signalr-rs. I'm having issues getting the Rust signalr-rs code to connect.

I would be happy to contribute working code (server and client) if you like, once I can get the Rust client working.

This is the working C# for the console client:

public class SignalRConnection
{
    public async void Start()
    {
        var url = "https://localhost:5001/chathub"; 

        var hubConnection = new HubConnectionBuilder()
            .WithUrl(url)
            .WithAutomaticReconnect()
            .Build();

        // Avoid certificate errors for now
        ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

        // receive a message from the hub
        hubConnection.On<string, string>("ReceiveMessage", (user, message) => OnReceiveMessage(user, message));

        var task = hubConnection.StartAsync();

        task.Wait();

        // send a message to the hub
        await hubConnection.InvokeAsync("SendMessage", "ConsoleApp", "Message from the console app");
    }

    private void OnReceiveMessage(string user, string message)
    {
        Console.WriteLine($"{user}: {message}");
    }
}

This is my in-progress but not working Rust "equivalent":

#[actix_rt::main]
async fn main() -> io::Result<()> {
env_logger::init();

println!("SignalR Console Rust Client");

let url = Url::parse("https://localhost:5001/");

let hub = "chathub";
let handler = Box::new(ChatHubHandler { hub: hub.to_string() });

// Set up the SSL connector so verification can be turned off for now
let mut builder = SslConnector::builder(SslMethod::tls()).unwrap();
builder.set_verify(openssl::ssl::SslVerifyMode::NONE); // avoid certificate errors for now
let connector = builder.build();

let client = HubClientBuilder::with_hub_and_url(hub, url.unwrap())
    .ssl_connector(connector)
    .start_supervised(handler)
    .await;

println!("Client started");

match client {
    Ok(addr) => {
        addr.do_send(HubQuery::new(
            hub.to_string(),
            "SendMessage".to_string(),
            vec!["Rust Console App"],
            "Message from the Rust console app".to_string(),
        ));
    }
    Err(e) => {
        println!("Hub client error : {:?}", e);
        System::current().stop();
    }
}

actix_rt::signal::ctrl_c().await

}

I get this output:

SignalR Console Rust Client
Client started
Hub client error : ParseError(Error("expected value", line: 1, column: 1))

I'd be happy to upload the server code in a PR. It's just the code from Microsoft's SignalR example.

Failed to connect to host: error:16000069

error:

Hub client error : RequestError("Failed to connect to host: error:16000069:STORE routines:ossl_store_get0_loader_int:unregistered scheme:crypto\\store\\store_register.c:237:scheme=C, error:1608010C:STORE routines:inner_loader_fetch:unsupported:crypto\\store\\store_meth.c:359:No store loader found. For standard store loaders you need at least one of the default or base providers available. Did you forget to load them? Info: Global default library context, Scheme (C : 0), Properties (<null>), error:16000069:STORE routines:ossl_store_get0_loader_int:unregistered scheme:crypto\\store\\store_register.c:237:scheme=file, error:80000002:system library:file_open:reason(2):providers\\implementations\\storemgmt\\file_store.c:267:calling stat(C:\\Users\\myname\\Downloads\\cloneanddownloadtemp\\vcpkg\\packages\\openssl_x64-windows-static-md/certs), error:16000069:STORE routines:ossl_store_get0_loader_int:unregistered scheme:crypto\\store\\store_register.c:237:scheme=C, error:1608010C:STORE routines:inner_loader_fetch:unsupported:crypto\\store\\store_meth.c:359:No store loader found. For standard store loaders you need at least one of the default or base providers available. Did you forget to load them? Info: Global default library context, Scheme (C : 0), Properties (<null>), error:16000069:STORE routines:ossl_store_get0_loader_int:unregistered scheme:crypto\\store\\store_register.c:237:scheme=file, error:80000002:system library:file_open:reason(2):providers\\implementations\\storemgmt\\file_store.c:267:calling stat(C:\\Users\\myname\\Downloads\\cloneanddownloadtemp\\vcpkg\\packages\\openssl_x64-windows-static-md/certs), error:16000069:STORE routines:ossl_store_get0_loader_int:unregistered scheme:crypto\\store\\store_register.c:237:scheme=C, error:1608010C:STORE routines:inner_loader_fetch:unsupported:crypto\\store\\store_meth.c:359:No store loader found. For standard store loaders you need at least one of the default or base providers available. Did you forget to load them? Info: Global default library context, Scheme (C : 0), Properties (<null>), error:16000069:STORE routines:ossl_store_get0_loader_int:unregistered scheme:crypto\\store\\store_register.c:237:scheme=file, error:80000002:system library:file_open:reason(2):providers\\implementations\\storemgmt\\file_store.c:267:calling stat(C:\\Users\\myname\\Downloads\\cloneanddownloadtemp\\vcpkg\\packages\\openssl_x64-windows-static-md/certs), error:16000069:STORE routines:ossl_store_get0_loader_int:unregistered scheme:crypto\\store\\store_register.c:237:scheme=C, error:1608010C:STORE routines:inner_loader_fetch:unsupported:crypto\\store\\store_meth.c:359:No store loader found. For standard store loaders you need at least one of the default or base providers available. Did you forget to load them? Info: Global default library context, Scheme (C : 0), Properties (<null>), error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:ssl\\statem\\statem_clnt.c:1888:")

code:

use std::io;

use url::Url;

use serde::de::DeserializeOwned;
use serde::Deserialize;
use serde_json::Value;

use signalr_rs::hub::client::{
    HubClientBuilder, HubClientError, HubClientHandler, HubQuery, PendingQuery,
};

use actix::System;
use actix_rt;

struct LivetimingHandler {
    hub: String,
}

impl HubClientHandler for LivetimingHandler {
    fn on_connect(&self) -> Vec<Box<dyn PendingQuery>> {
        let topics = vec!["Heartbeat", "WeatherData", "SPFeed"];
        topics
            .into_iter()
            .enumerate()
            .map(|(idx, topic)| {
                Box::new(HubQuery::new(
                    self.hub.to_string(),
                    "Subscribe".to_string(),
                    vec![topic.to_string()],
                    (idx + 1).to_string(),
                )) as Box<dyn PendingQuery>
            })
            .collect()
    }
    fn error(&self, _id: Option<&str>, _msg: &Value) {}
    fn handle(&mut self, method: &str, _message: &Value) {
        /*
        match method {
        }
        */
        println!("Method {}", method);
        //println!("Message {}", message);
    }
}

#[actix_rt::main]
async fn main() -> io::Result<()> {
    let hub = "Streaming";
    let handler = Box::new(LivetimingHandler {
        hub: hub.to_string(),
    });
    let client = HubClientBuilder::with_hub_and_url(
        hub,
        Url::parse("https://livetiming.formula1.com/signalr").unwrap(),
    )
    .start_supervised(handler)
    .await;

    match client {
        Ok(addr) => {
            println!("{}", &addr.connected());
            println!("Client Started");
        }
        Err(e) => {
            println!("Hub client error : {:?}", e);
            System::current().stop();
        }
    }
    actix_rt::signal::ctrl_c().await
}

Need full example building instructions

Could you please provide the instructions for building the bittrex.rs example? Does it need a cargo.toml file? Stable or Nightly Rust? Tips on openssl crate(s) used? Platform(s) used for the example instructions?

Thank-you very much in advance.

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.