加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 加载测试SignalR集线器应用程序的最佳方法是什么

发布时间:2020-12-16 00:43:57 所属栏目:asp.Net 来源:网络整理
导读:我想知道一些用于测试基于SignalR集线器的应用程序的不同方法。 解决方法 @ElHaix从我自己测试中看到的方法,你的方法不是创建一个新的连接,而是重用现有的连接。当您循环查看profileID的集合时,您应该看到hubConnection.ConnectionID保持不变。为了创建一
我想知道一些用于测试基于SignalR集线器的应用程序的不同方法。

解决方法

@ElHaix从我自己测试中看到的方法,你的方法不是创建一个新的连接,而是重用现有的连接。当您循环查看profileID的集合时,您应该看到hubConnection.ConnectionID保持不变。为了创建一个新的连接,你需要在foreach循环中创建一个HubConnection实例。
int successfulConnections = 0;
        const int loopId = 10;

        Console.WriteLine("Starting...");
        for (int i = 1; i <= loopId; i++)
        {
            Console.WriteLine("loop " + i);

            var hubConnection = new HubConnection(HUB_URL);
            IHubProxy chatHub = hubConnection.CreateProxy(HUB_NAME);

            Console.WriteLine("Starting connection");
            hubConnection.Start().Wait();
            Console.WriteLine("Connection started: " + hubConnection.ConnectionId);

            chatHub.Invoke("Register","testroom").ContinueWith(task2 =>
            {
                if (task2.IsFaulted)
                {
                    Console.WriteLine(String.Format("An error occurred during the method call {0}",task2.Exception.GetBaseException()));
                }
                else
                {
                    Console.WriteLine("Connected: " + hubConnection.ConnectionId);
                    successfulConnections++;
                }
            });

            Thread.Sleep(1000);
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读