在 C/Linux 中,很容易为每个KEEPALIVE 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 (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 (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中,如何设置socket的三个socket选项?我知道没有可移植的方法来解决它,但只能在 Linux 中,我可以设置那些套接字选项吗?
最佳答案
给出的链接实际上并没有告诉您如何使用 JNA 来实现它。在花了一段时间研究 SO 以寻找解决方案后,我编写了自己的库。你可以找到它here .
关于java - 如何在 java 或 netty 中设置套接字选项(TCP_KEEPCNT、TCP_KEEPIDLE、TCP_KEEPINTVL)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22472844/