从 SignalR 调用特定客户端
我想从服务器调用特定客户端,而不是广播给所有客户端。问题是我在一些 AJAX 请求的范围内(比如说在 .aspx 代码隐藏中),而不是在 Hub 或 PersistentConnection 中,所以没有 Clients 属性 - 并且进行 ajax (jquery) 调用的客户端不是客户端我想发送信号器消息!
现在,我有一个在 JS 页面加载时调用的集线器,它将新客户端注册到服务器静态列表中,所以我有客户端 Guid。但不知道如何使用它将消息从服务器发送到特定客户端。
I want to call specific client from server, and not broadcast to all of them. Problem is that I'm in scope of some AJAX request (in .aspx codebehind let say), and not in Hub or PersistentConnection, so don't have Clients property - and client who made that ajax (jquery) call is not the client I want to send signalr message!
Now, I have one hub that it's called on JS page load, which registers new client into server static list, so I have client Guids. But don't know how to use that to send message from server to specific client.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在服务器端发送客户端的 id 并响应该 id
at server side send the id of the client and response to that id
每次您向中心服务器发送请求时,您的请求都会有不同的连接 ID,因此,我添加了一个包含用户名的静态哈希表 -
不会连续变化,并且信号 r 的连接 id,每次连接时,连接 id 都会更新
,并在服务器代码中:
Every time you send a request to the hub server, your request will have a different connection id, so, I added a static hash table that contains a username- which
is not changing continuously, and a connection id fro the signal r,every time you connect, the connection id will be updated
and in the server code:
当你想向特定id发送消息时
when you want to send a message to specific id
如果特定用户实际上是调用者本身,您可以使用:
If the specific user actually is the caller it self, you can use: