Broadcasting message to all clients except self in SignalR

后端 未结 2 822
不思量自难忘°
不思量自难忘° 2021-02-02 10:18

I realize that these questions are similar:

SignalR - Broadcast to all clients except Caller

Send a message to all clients in a Group, except for the current cl

相关标签:
2条回答
  • 2021-02-02 10:34

    Your approach does work, however the correct approach is to use the built in API: Clients.Others.addMessage(message). Also there's no need to get the hub context inside the hub itself. You can always access the current connection ID via Context.ConnectionId or send message sto clients via Clients.All.foo();

    And you cannot set the ConnectinoID programatically. If you'd like to track users across pages maintain a list of users on your server and then just re-assign the connection id's as they navigate through the site.

    Here's a post explaining the tracking of users: SignalR 1.0 beta connection factory

    0 讨论(0)
  • 2021-02-02 10:35

    If you're sending the message in a method on the Hub class, you can also use Clients.Others to exclude the calling client. You only need to use AllExcept(id) if you're not in a hub method.

    See the following for details:

    http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-server#selectingclients

    0 讨论(0)
提交回复
热议问题