dtuzjzs3853 2017-08-31 19:31
浏览 272

为什么grpc服务器示例使用net.Listen而不是tls.Listen [关闭]

I'm setting up a golang grpc server that will use TLS for client authorization/authentication. All the examples of server setup that I've seen use net.Listen() instead of tls.Listen(). Why is this?

import (
    "crypto/tls"
    "github.com/pkg/errors"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials"
    "net"
)

func startGRPCListener(hostport string, tlsconfig *tls.Config) (grpcServer *grpc.Server) {
    listener, _ = net.Listen("tcp", hostport)
    cred := grpc.Creds(credentials.NewTLS(tlsconfig))
    grpcServer := grpc.NewServer(cred)
    go func() {
        serveErr := grpcServer.Serve(listener)
        log.WithError(serveErr).Info("GRPC server exited")
    }() 

    return
}

I've noticed in a couple of working examples if I swap to tls.Listen, the connection can no longer be made. However, in other cases, this doesn't cause a problem!

I guess my question is "should I use net.Listen or tls.Listen, or does it not make a difference?"

  • 写回答

1条回答 默认 最新

  • duanfu3884 2017-08-31 19:34
    关注

    Why is this?

    Because these are examples about grpc and not about TLS? Examples tend to be examples: Simplifications to demonstrate something. Examples are not copy-paste samples for production code.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大