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.
SignalR provides an API for creating server-to-client remote procedure calls (RPC). The RPCs invoke functions on clients from server-side .
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).
ASP.NET Core SignalR supports two protocols for encoding messages: JSON and MessagePack.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With