如何在Java或Netty中设置套接字选项(TCP_KEEPCNT,TCP_KEEPIDLE,TCP_KEEPINTVL)? [英] How to set socket option (TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL) in java or netty?

查看:672
本文介绍了如何在Java或Netty中设置套接字选项(TCP_KEEPCNT,TCP_KEEPIDLE,TCP_KEEPINTVL)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C/Linux中,很容易为每个 KEEPALIVE tcp连接独立地设置不同的套接字选项值.

In C/Linux, it's easily to set different value about those socket options for every KEEPALIVE tcp connection independently.

TCP_KEEPCNT(从Linux 2.4开始) TCP在断开连接之前应发送的最大保持活动探测数.此选项不应在旨在可移植的代码中使用.

TCP_KEEPCNT (since Linux 2.4) The maximum number of keepalive probes TCP should send before dropping the connection. This option should not be used in code intended to be portable.

TCP_KEEPIDLE(从Linux 2.4开始) 如果已在套接字上设置套接字选项SO_KEEPALIVE,则在TCP开始发送保持活动探测之前,连接需要保持空闲时间(以秒为单位). 此选项不应在旨在可移植的代码中使用.

TCP_KEEPIDLE (since Linux 2.4) The time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes, if the socket option SO_KEEPALIVE has been set on this socket. This option should not be used in code intended to be portable.

TCP_KEEPINTVL(从Linux 2.4开始) 各个keepalive探针之间的时间(以秒为单位).此选项不应在旨在可移植的代码中使用.

TCP_KEEPINTVL (since Linux 2.4) The time (in seconds) between individual keepalive probes. This option should not be used in code intended to be portable.

在netty或java中,如何为套接字设置三个套接字选项?我知道没有可移植的方法来解决它,但是只有在Linux中,我才能设置这些套接字选项吗?

In netty or java, how to set the three socket options for socket? I know there is no portable way to solve it, but only in Linux, can I set those socket options?

推荐答案

给出的链接实际上并没有告诉您如何使用JNA来实现它.花了一段时间在SO上四处寻找解决方案之后,我编写了自己的库.您可以在此处找到它.

The link given doesn't actually tell you how to use JNA to implement it. Having spent a while digging around on SO to find solutions, I wrote my own library. You can find it here.

这篇关于如何在Java或Netty中设置套接字选项(TCP_KEEPCNT,TCP_KEEPIDLE,TCP_KEEPINTVL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆