gpt4 book ai didi

asp.net-mvc - 带有 Redis 的 SignalR 将消息发送到特定的 ConnectionID

转载 作者:可可西里 更新时间:2023-11-01 11:01:50 27 4
gpt4 key购买 nike

I am using SingalR for my Chat Application. Wanted to play with Redis and SignalR but I cannot find an working example where i can send msg to specific connectionId. Below Code that works for a single server instance. But when i make it a Web Garden with 3 process it stops working as my server instance that gets the message cannot find the connectionId for that destination UserId to send the message.

private readonly static ConnectionMapping<string> _connections = new ConnectionMapping<string>();
public void Send(string sendTo, string message, string from)
{
string fromclientid = Context.QueryString["clientid"];

foreach (var connectionId in _connections.GetConnections(sendTo))
{
Clients.Client(connectionId).send(fromclientid, message);

}

Clients.Caller.send(sendTo, "me: " + message);

}

public override Task OnConnected()
{
int clientid = Convert.ToInt32(Context.QueryString["clientid"]);

_connections.Add(clientid.ToString(), Context.ConnectionId);

}

I have used the example below to setup my box and code but none of them have examples for sending from one client to specific client or group of specific clients.

http://www.asp.net/signalr/overview/performance-and-scaling/scaleout-with-redis
https://github.com/mickdelaney/SignalR.Redis/tree/master/Redis.Sample

最佳答案

Hub 类中的 ConnectionMapping 实例不会在不同的 SignalR 服务器实例之间同步。您需要使用永久性外部存储,例如数据库或 Windows Azure 表。有关详细信息,请参阅此链接:

http://www.asp.net/signalr/overview/hubs-api/mapping-users-to-connections

关于asp.net-mvc - 带有 Redis 的 SignalR 将消息发送到特定的 ConnectionID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17915655/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com