gpt4 book ai didi

c# - SignalR 连接问题 - 连接监听器无法接受任何新连接

转载 作者:行者123 更新时间:2023-12-05 03:24:28 25 4
gpt4 key购买 nike

我有一个使用 ASPNet Core SignalR 集线器 (GameServer) 的游戏服务器,以及一个使用 ASPNet Core SignalR 客户端库 (GameClient) 的客户端。我已经成功地在两者之间建立了联系并传递了一些消息。

中间还有一个类库,抽象出一些服务端和客户端都会用到的东西(GameInteraction)。 GameInteraction 是一个 .Net Standard 库(我在客户端使用 Unity3d,因此该库需要在 .Net Standard 中)。

在 GameInteraction 中,我为 Microsoft.AspNetCore.SignalR.Client.HubConnection 添加了一些扩展方法,如下所示。我在 GameClient 中使用这些方法来调用一些 GameServer 函数,而不必确保客户端知道要调用哪些方法。

   public static async Task<string> CreateGame(this HubConnection connection)
{
var gameId = await connection.InvokeAsync<string>(nameof(IServer.CreateGame));
return gameId;
}

public static async Task JoinGame(this HubConnection connection, string playerName, string gameId)
{
await connection.InvokeAsync(nameof(IServer.JoinGame), playerName, gameId);
}

现在,每当 GameClient 尝试与服务器建立连接时,我都会收到以下错误。

Microsoft.AspNetCore.Server.Kestrel[0]
The connection listener failed to accept any new connections.
System.MissingMethodException: Method not found: 'Microsoft.AspNetCore.Http.Features.IFeatureCollection Microsoft.AspNetCore.Connections.ConnectionContext.get_Features()'.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelConnection..ctor(Int64 id, ServiceContext serviceContext, ConnectionDelegate connectionDelegate, ConnectionContext connectionContext, IKestrelTrace logger)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ConnectionDispatcher.<>c__DisplayClass8_0.<<StartAcceptingConnectionsCore>g__AcceptConnectionsAsync|0>d.MoveNext()

我感觉这是因为我使用的 SignalR 库之间有些不匹配,即使我对所有三个项目都使用 ASPNet Core 版本。请注意,如果我删除了扩展方法,但没有从 GameInteraction 中删除 SignalR.Client 库,仍然无法建立连接。只有当我从 GameInteraction 中完全删除该库后,一切才能恢复正常。

有人可以插入我寻求解决方案吗?提前致谢。

最佳答案

在服务器项目中使用“.NET Core 3.1”作为目标框架时,我得到了 MissingMethodException ConnectionContext.get_Features(),但安装了最新的 6.0.x 版本的 Microsoft.AspNetCore.SignalR.Client。

Target Framework 和 SignalR 客户端的版本号需要对应,所以我通过将 NuGet 包管理器中的 SignalR.Client 包更新为 3.1.25 解决了这个问题

关于c# - SignalR 连接问题 - 连接监听器无法接受任何新连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72296069/

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