代码拉取完成,页面将自动刷新
gRPC sends HTTP2 pings on the transport to detect if the connection is down. If the ping is not acknowledged by the other side within a certain period, the connection will be closed. Note that pings are only necessary when there is no activity on the connection.
It should be sufficient for most users to only change interval
and timeout
properties, but the
following properties can also be useful in certain use cases.
Property | Client | Server | Description |
---|---|---|---|
interval | Int64.max (disabled) | .hours(2) | The amount of time to wait before sending a keepalive ping. |
timeout | .seconds(20) | .seconds(20) | The amount of time to wait for an acknowledgment. This value must be less than interval . |
permitWithoutCalls | false | false | Send keepalive pings even if there are no calls in flight. |
maximumPingsWithoutData | 2 | 2 | Maximum number of pings that can be sent when there is no data/header frame to be sent/ |
minimumSentPingIntervalWithoutData | .minutes(5) | .minutes(5) | If there are no data/header frames being received: the minimum amount of time to wait between successive pings. |
minimumReceivedPingIntervalWithoutData | N/A | .minutes(5) | If there are no data/header frames being sent: the minimum amount of time expected between receiving successive pings. If the time between successive pings is less than this value, then the ping will be considered a bad ping from the peer. Such a ping counts as a "ping strike". |
maximumPingStrikes | N/A | 2 | Maximum number of bad pings that the server will tolerate before sending an HTTP2 GOAWAY frame and closing the connection. Setting it to 0 allows the server to accept any number of bad pings. |
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let keepalive = ClientConnectionKeepalive(
interval: .seconds(15),
timeout: .seconds(10)
)
let channel = try GRPCChannelPool.with(
target: .host("localhost"),
transportSecurity: .tls(...),
eventLoopGroup: group
) {
// Configure keepalive.
$0.keepalive = keepalive
}
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let keepalive = ServerConnectionKeepalive(
interval: .seconds(15),
timeout: .seconds(10)
)
let configuration = Server.Configuration(
target: .hostAndPort("localhost", 443),
eventLoopGroup: group,
connectionKeepalive: keepalive,
serviceProviders: [YourCallHandlerProvider()]
)
let server = Server.makeBootstrap(configuration: configuration)
Fore more information, please visit the gRPC Core documentation for keepalive
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。