Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Parameter/Query in HubConnection SignalR Core

Tags:

I'm trying to add parameter into connection to signalr.

I'm using Builder to create my Client connection and start it:

var connection = new HubConnectionBuilder()         .WithUrl("http://10.0.2.162:5002/connection")         .WithConsoleLogger()         .WithMessagePackProtocol()         .WithTransport(TransportType.WebSockets)         .Build();  await connection.StartAsync(); 

I want to send a simple parameter in this connection: Something Like:

"Token": "123"

In my server side i think i can take this parameter from HttpContext:

public override Task OnConnectedAsync() {     var httpContext = Context.Connection.GetHttpContext();     var token = httpContext.Request.Query["Token"];     return base.OnConnectedAsync(); } 

Any idea of how to send this parameter? Thanks.

like image 313
Pedro Franco Avatar asked Feb 28 '18 21:02

Pedro Franco


People also ask

Is SignalR an RPC?

SignalR provides an API for creating server-to-client remote procedure calls (RPC). The RPCs invoke functions on clients from server-side .

How many connections SignalR can handle?

In the default mode, the app server creates five server connections with Azure SignalR Service. The app server uses the Azure SignalR Service SDK by default. In the following performance test results, server connections are increased to 15 (or more for broadcasting and sending a message to a big group).

Does SignalR use JSON?

ASP.NET Core SignalR supports two protocols for encoding messages: JSON and MessagePack.


1 Answers

I have found how to do this after much research:

On my build i just send the token from url connection. Like this:

var connection = new HubConnectionBuilder()         .WithUrl($"http://10.0.2.162:5002/connection?token={token}")         .WithConsoleLogger()         .WithMessagePackProtocol()         .WithTransport(TransportType.WebSockets)         .Build(); 
like image 60
Pedro Franco Avatar answered Nov 20 '22 03:11

Pedro Franco