SignalR self hosted windows service, listening for messages

♀尐吖头ヾ 提交于 2019-11-30 23:23:39
rdoubleui

In general SignalR offers a real-time messaging environment with the benefit that it can push messages to clients without them requesting the update (you've read the intro, so enough for that). Whether you start your self-host from within a service shouldn't make a difference.

From what I understand from your scenario: You need to consume the messages from the self-hosted service. I think you might only need a hint to the SignalR Desktop Client. I think your app/service should start off the service and then act as a client to the service itself. This would be the cleanest approach.

As the javascript client it acts as a consumer of the service with the same capabilities:

HubConnection conn = new HubConnection("http://192.168.1.1:8080");
IHubProxy hub = conn.CreateHubProxy("ChatHub");

// call from hub to client
hub.On<string, string>("addMessage", (name, message) =>
{
     // Handle incoming data update
});

and vice versa from the desktop client to the hub:

await hub.Invoke<string, string>("Send", name, message);

To work with groups, the logic needs to be defined within your hub. The documentation Working with groups gives an understandable overview.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!