문제

Signalr의 최신 버전을 사용하고 있습니다.그러나 최근에 흥미로운 확장 문제를 해결합니다. Signalr은 모든 클라이언트의 모든 클라이언트 그룹을 쿼리 문자열의 클라이언트에서 보냅니다.시스템은 사용자가 가입 한 모든 프로젝트를 나타내는 모든 프로젝트를 나타내는 수많은 그룹에 참여하고 있으며, 이들 중 하나에 대한 알림을 받아야합니다.

이 많은 수의 그룹 (및 ID에 대한 GUID를 사용하는 것)이 QueryString이 최대 크기에 도달하여 작동을 멈추게하는 신호입니다.

이것은 요청 Webform (Azure 버그에 대해 긴 폴링을 사용하여) 요청 웹 폼에 표시됩니다.

transport   longPolling
connectionId    bbed6f35-8379-4be3-ac28-ef3e618382ae
connectionData  [{"name":"jethub"}]
messageId   85
groups  ["JetHub.f9f81bcc-8417-46bd-bae5-c4134972601d","JetHub.5139a8de-04c2-48da-9427-39666e52fabd","JetHub.6b12e333-4d22-47c3-8587-7a9ad5026184","JetHub.252ea279-7a71-40e7-b03c-7d63e69f07ab","JetHub.a4843a77-1e6d-4693-b3de-b392ef465410","JetHub.27feb53a-3c2d-4b11-92f7-dbdffb874b25","JetHub.8840dfcf-e6be-4b72-965b-b282a60446e8","JetHub.bf7d3301-6fc0-4499-bee8-fe22f1bc2281","JetHub.655cba0e-7f72-402c-b80b-dcb740546163","JetHub.85d817e2-67a3-4291-b564-5320598339f6","JetHub.e3079263-3f6e-4a54-ad88-0dfc5dd2ce18","JetHub.33f00a67-9b05-4293-8119-4617e2fed9b0","JetHub.6323cfe8-fb81-4716-b553-79b9d72641a5","JetHub.b4359f8a-030a-4ac9-aacd-c05b42163bcc", ... many more]
.

IIS에서 QueryString 크기를 늘릴 수는 있지만 그룹을 관리하는 더 좋은 방법이 있거나 서버 측 그룹 구성 체계를 만들고 각 클라이언트에 개별적으로 브로드 캐스팅해야합니까?그 점에서 지속적으로 도움이 될 수 있습니까?

감사합니다.

도움이 되었습니까?

해결책

As groups are roundtripped via the query string in SignalR 0.5.3, you have the following options: a) increase the maximum query string size b) use shorter group names c) handle grouping yourself on the server and broadcast seperately to each user

PersistentConnections won't help here as the Hub API is built on top of them, so you'll run into the same problem.

다른 팁

I know that this has already been answered to your satisfaction, but there is a way of managing groups on the server without sending messages to each client individually. You can implement your own HubDispatcher:

using System.Collections.Generic;
using SignalR;
using SignalR.Hubs;

namespace My.Hubs
{
    public class MyHubDispatcher : HubDispatcher
    {
        public MyHubDispatcher() : base("/myhubs") { }

        protected override Connection CreateConnection(string connectionId, IEnumerable<string> signals, IEnumerable<string> groups)
        {
            //ex: IEnumerable<string> myGroups = new string[] { "MyHub.MyGroup", "MyHub.MyOtherGroup", "MyOtherHub.MyGroup" };
            IEnumerable<string> myGroups = GetGroups(connectionId);
            return base.CreateConnection(connectionId, signals, myGroups);
        }
    }
}

You can then set up routing like any other PersistentConnection:

using System.Web;
using System.Web.Routing;
using SignalR;

namespace My
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class Application : HttpApplication
    {
        protected void Application_Start()
        {
            RouteTable.Routes.MapConnection<Hubs.MyHubDispatcher>("myhubs", "myhubs/{*operation}");
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
    }
}

Then you can use groups on you Hubs like you normally would:

using SignalR.Hubs;

namespace My.Hubs
{
    public class MyHub : Hub
    {
        public void AlertClients(string id, int duration)
        {
            Clients["MyGroup"].Alert("MyGroup");
            Clients["MyOtherGroup"].Alert("MyOtherGroup");
        }
    }
}

If you using the JS client you can simply include the script at ~/myhubs/hubs instead of ~/signalr/hubs. If you are using the .NET client you just use new Client.Hubs.HubConnection("http://foo/myhubs", useDefaultUrl: false);

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top