简体   繁体   中英

GRCP Server throws exception when using SSLServerCredentials in C#

So im currently trying to set up a grpc server with ssl enabled but i always get the exception "Failed to bind port "0.0.0.0:8888" The port is definitely not in use. If it is important in server.crt the CN is localhost. It also works perfectly fine with ServerCredentials.Insecure

UPDATE: I got the server working, i had an issue with the certificate, however now now the client can't connect and i get an RpcException with StatusCode=Unavailable, Detail="Empty update"

var cacert = File.ReadAllText($"{path}/ca.crt");
        var servercert = File.ReadAllText($"{path}/server.crt");
        var serverkey = File.ReadAllText($"{path}/server.key");
        var keypair = new KeyCertificatePair(servercert, serverkey);
        var sslCredentials = new SslServerCredentials(new List<KeyCertificatePair> { keypair }, cacert, true);

        var server = new Server
        {
            Services = { Comm.BindService(new Communicator()) },
            Ports = { new ServerPort("0.0.0.0", 8888, sslCredentials) }
        };
        server.Start();

        Console.WriteLine("Server started");
        Console.ReadKey();

        server.ShutdownAsync().Wait();

It was a certificate issue. https://github.com/grpc/grpc-dotnet in this repo is an example with certificates in case anyone else is struggling

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM