【问题标题】:Exception "failed to connect to all addresses" in gRpc Unity3D client and ASP.Net core servergRpc Unity3D 客户端和 ASP.Net 核心服务器中的异常“无法连接到所有地址”
【发布时间】:2021-09-21 11:41:14
【问题描述】:

我用控制台客户端测试了 grcp asp.net 服务器,它正在工作。当然第一个问题是认证问题,但是在客户端上安装认证后它就开始工作了。

现在我正在使用 Unity3D 版本 2021.1.2f1 的新客户端测试同一台服务器。我在教程中将项目设置为 .NET 4.x。安装插件 grcp 以实现统一。但是出了点问题。我觉得可能是认证有问题,但是有没有办法为统一客户端安装认证? Unity 不支持 http2,所以我可能需要在服务器和客户端中配置它,还是自动配置?可能是另一个问题,但我无法想象是什么。

我在下面遇到异常。

RpcException: Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1626079380.128000000","description":"Failed to pick subchannel","file":"..\..\..\src\core\ext\filters\client_channel\client_channel.cc","file_line":3009,"referenced_errors":[{"created":"@1626079380.128000000","description":"failed to connect to all addresses","file":"..\..\..\src\core\ext\filters\client_channel\lb_policy\pick_first\pick_first.cc","file_line":398,"grpc_status":14}]}")
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
GameManager+<Start>d__1.MoveNext () (at Assets/GameManager.cs:29)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <9244fb8344e84288877b43b45b29c242>:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

原始文件

syntax = "proto3";

option csharp_namespace = "GameNetRpc";

package game;

service GameNet {
  rpc SayHello (HelloRequest) returns (HelloReply);
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

启动设置

{
  "profiles": {
    "AspGrpcServer": {
      "commandName": "Project",
      "dotnetRunMessages": "true",
      "launchBrowser": false,
      "applicationUrl": "http://localhost:5000;https://localhost:5001",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

客户端代码

using GameNetRpc;
using Grpc.Core;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    private Channel _channel;
    private async void Start()
    {
        _channel = new Channel("localhost", 5001, ChannelCredentials.Insecure);
        var client = new GameNet.GameNetClient(_channel);
        var reply = await client.SayHelloAsync(new HelloRequest { Name = "Client unity" });
        Debug.Log("Response from server: " + reply.Message);
    }

    private void OnDestroy()
    {
        _channel.ShutdownAsync().Wait();
    }
}

【问题讨论】:

标签: c# asp.net asp.net-core unity3d grpc


【解决方案1】:

我开始使用MagicOnion,发现错误herehttps://github.com/Cysharp/MagicOnion/#support-for-unity-client的解决方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-22
    • 2021-06-03
    • 2020-10-13
    • 2020-01-27
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 2021-12-06
    相关资源
    最近更新 更多