keepalive

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 4 Imported by: 2

README

keepalive

使用示例

grpc server
func getServerOptions() []grpc.ServerOption {
	var options []grpc.ServerOption
	// 默认是每15秒向客户端发送一次ping,修改为间隔20秒发送一次ping
	options = append(options, keepalive.ServerKeepAlive()...)

	return options
}

func main() {
	server := grpc.NewServer(getServerOptions()...)

	list, err := net.Listen("tcp", addr)
	if err != nil {
		panic(err)
	}

    // ......
}

grpc client
func getDialOptions() []grpc.DialOption {
	var options []grpc.DialOption

	// 禁止tls加密
	options = append(options, grpc.WithTransportCredentials(insecure.NewCredentials()))

	// keepalive option
	options = append(options, keepalive.ClientKeepAlive())

	return options
}

func main() {
	conn, err := grpc.Dial("127.0.0.1:8080", getDialOptions()...)
	if err != nil {
		panic(err)
	}

	// ......
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientKeepAlive

func ClientKeepAlive() grpc.DialOption

ClientKeepAlive 保持连接设置

func ServerKeepAlive

func ServerKeepAlive() []grpc.ServerOption

ServerKeepAlive 保持连接设置

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL