asp.net-core-signalr

In ASP.NET Core SignalR, how do I send a message from the server to a client?

那年仲夏 提交于 2019-12-06 18:51:59
问题 I've successfully setup a SignalR server and client using the newly released ASP.NET Core 2.1. I built a chat room by making my ChatHub extend Hub : whenever a message comes in from a client, the server blasts it back out via Clients.Others . What I do not yet understand is how to send a message to clients not as a response to an incoming message. If the server is doing work and produces a result, how do I gain access to the Hub in order to message particular clients? (Or do I even need

How to buffer messages on signal hub and send them when the right client appears?

随声附和 提交于 2019-12-06 15:56:34
I hawe two type of clients connecting my signalR server (ASP.NET Core). Some of them are senders, and some of them are receivers. I need to route messages from senders to the receivers, which is not a problem, but when there is no receivers, I need to somehow buffer messages and not lose them (probably the best is ConcurrentQueue in some kind of a singleton class) but when the first receiver connect, the message buffer needs to start dequeue. Which is the best approach for this? I created singleton class that wraps arround ConcurrentQueue collection and I enqueue and dequeue messages there.

AspNetCore.SignalR : Cannot start a connection that is not in the Initial state

江枫思渺然 提交于 2019-12-05 16:28:13
I have troubles to get my ASP.NET Core SignalR app working. I have this server-side code : public class PopcornHub : Hub { private int Users; public async Task BroadcastNumberOfUsers(int nbUser) { await Clients.All.InvokeAsync("OnUserConnected", nbUser); } public override async Task OnConnectedAsync() { Users++; await BroadcastNumberOfUsers(Users); await base.OnConnectedAsync(); } public override async Task OnDisconnectedAsync(Exception exception) { Users--; await BroadcastNumberOfUsers(Users); await base.OnDisconnectedAsync(exception); } } whose SignalR Hub service is configured as : public

ASP.NET CORE 2.1 Server timeout while debugging

Deadly 提交于 2019-12-05 03:47:21
'Error: Server timeout elapsed without receiving a message from the server.'. I'm trying to debug some server-side code and while I do that the client gets disconnected in less than a minute. I'm only using SignalR to communicate to clients, without controllers yet. Is there any setting that can disable timeout or at least make it way longer than it is now? my launchSettings.json: { "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:26793", "sslPort": 44386 } }, "profiles": { "IIS Express": { "commandName":

In ASP.NET Core SignalR, how do I send a message from the server to a client?

主宰稳场 提交于 2019-12-05 00:22:39
I've successfully setup a SignalR server and client using the newly released ASP.NET Core 2.1. I built a chat room by making my ChatHub extend Hub : whenever a message comes in from a client, the server blasts it back out via Clients.Others . What I do not yet understand is how to send a message to clients not as a response to an incoming message. If the server is doing work and produces a result, how do I gain access to the Hub in order to message particular clients? (Or do I even need access to the Hub ? Is there another way to send messages?) Searching this issue is difficult as most

Using SignalR Core to send messages from a Controller Method to Angular

爱⌒轻易说出口 提交于 2019-12-04 06:55:17
I'm trying to use SignalR for Asp Net Core 2.1 in order to send a message from a controller method which call is triggered from a test button in Angular. The behavior I'd expect is that when I click the button, my service invokes the controller method, which sends the test message. Then, I will simply log the message. I want to manage this in a service in order to avoid code duplication in all of the components. I've read some examples like this question about using SignalR in a service (I've used the second solution) and this article and the official docs but even with applying these concepts

signalr unity3d connection

房东的猫 提交于 2019-12-03 03:44:56
I am fairly new to signalr. Im using signalr core to make connection between unity and signalr but my code doesn't return me anything at all. That leaving me wondering if my code is actually working or not. After I've established connection, unity will wait for server side to call a function then it will execute what it need to do. here is my code : using System.Collections; using System.Collections.Generic; using UnityEngine; using Microsoft.AspNetCore.SignalR.Client; public class tyrNewSignalR : MonoBehaviour { void Start() { var connection = new HubConnectionBuilder() .WithUrl("http://api

How to authorize SignalR Core Hub method with JWT

人盡茶涼 提交于 2019-12-02 00:10:44
问题 I am using JWT authentication in my ASP.NET Core 2.0 application with OpenIddict. I am following idea in this thread and calling AuthorizeWithJWT method after SignalR handshake. But now, I do not know what should I set in AuthorizeWithJWT method so I can use [Authorize(Roles="Admin")] for example. I tried with setting context user, but it is readonly: public class BaseHub : Hub { public async Task AuthorizeWithJWT(string AccessToken) { //get user claims from AccesToken this.Context.User =

Connection ID when calling SignalR Core Hub method from Controller

拟墨画扇 提交于 2019-12-01 23:40:11
This is a follow-up to another question and answer . What's the effect of calling HubContext.Clients.Caller or HubContext.Clients.Others from the controller? I see it depends on the connection ID . What value would it have in this situation? If the connection ID (and thus Caller and Others ) is invalid then (from within the controller action) how could I obtain a connection ID (for the client currently calling the Web API) that I could use with HubContext.Clients 's methods? What's the effect of calling HubContext.Clients.Caller or HubContext.Clients.Others from the controller? I see it

How to authorize SignalR Core Hub method with JWT

时光怂恿深爱的人放手 提交于 2019-12-01 21:22:28
I am using JWT authentication in my ASP.NET Core 2.0 application with OpenIddict. I am following idea in this thread and calling AuthorizeWithJWT method after SignalR handshake. But now, I do not know what should I set in AuthorizeWithJWT method so I can use [Authorize(Roles="Admin")] for example. I tried with setting context user, but it is readonly: public class BaseHub : Hub { public async Task AuthorizeWithJWT(string AccessToken) { //get user claims from AccesToken this.Context.User = user; //error User is read only } } And using authorize attribute: public class VarDesignImportHub :