简体   繁体   English

检查使用 SignalR 的 Self Hosting 是否正在监听

[英]Check if Self Hosting With SignalR is listening

I am creating a console application that maintains an active Client/Server connection.我正在创建一个维护活动客户端/服务器连接的控制台应用程序。 To start the server I run:要启动我运行的服务器:

string url = "http://localhost:6118";  
using (WebApp.Start<Startup>(url))  
{  
     Console.WriteLine("The Server URL is: {0}", url);  
     Console.ReadLine();  
 }

My question is how to constantly check if the Server is receiving messages.我的问题是如何不断检查服务器是否正在接收消息。 I did not find any status properties indicating that everything is working correctly.我没有发现任何状态属性表明一切正常。

To check from a separate console application (client) - There are several lifetime events you can use to check your current state such as StateChanged or ConnectionSlow.从单独的控制台应用程序(客户端)进行检查 - 您可以使用几个生命周期事件来检查当前的 state,例如 StateChanged 或 ConnectionSlow。

hubConnection.ConnectionSlow += () => Console.WriteLine("Connection problems.");

Check the documentation for more information on the C# .NET Client - https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-net-client#how-to-handle-connection-lifetime-events查看文档以获取有关 C# .NET 客户端 - https: //docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-b-the-the-的更多信息如何处理连接生命周期事件

You could do something similar in a JavaScript client as well.您也可以在 JavaScript 客户端中执行类似的操作。

In the self host console application you could create a method for a client to invoke and have the hub respond back to your client to verify it is listening.在自主机控制台应用程序中,您可以创建一个方法供客户端调用并让集线器响应您的客户端以验证它正在侦听。 I do something similar from a "admin" page where once every few minutes through a setTimeout (Javascript) an invoke to the server is made.我从“管理”页面执行类似的操作,每隔几分钟通过 setTimeout (Javascript) 调用一次服务器。 The response updates my page and lets me know it is running.响应更新了我的页面并让我知道它正在运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM