Broadcasting message to all clients except self in SignalR

后端 未结 2 823
不思量自难忘°
不思量自难忘° 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

提交回复
热议问题