how to detect TCP keep alive packets and keep connection open

和自甴很熟 提交于 2019-12-25 18:25:35

问题


I wrote my own server with epoll. When I sent TCP keep alive packages from client to server, epoll event will not get triggered. Question: I want my server to keep the connection open when server gets tcp keep alive packages.

I also tried to look at tcp info but there are no update for its attributes when server got keep alive packages.

I understand tcp keep alive packages is no data but header. I saw in my tcpdump, kernel sent back tcp keep alive ACK after received keep alive package. My goal is to keep connection open when keep alive arrives (kind like reset timer in my server, my server can close connection in no tcp real data)

I set up my client to make connection and send data (e.g "hello world") then send keep alive packages to server.

My server is epoll triggered. I already also tried to set my server to be non-blocking.

// epoll setting I tested
EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET

(most questions I found on internet are related to client side, my question is more towards server or receiver side of tcp keep alive, how to keep it open)


回答1:


No, this is not possible as far as I know.

You will have to implement a heartbeat in the application protocol, and then you can stop using TCP keepalive.



来源:https://stackoverflow.com/questions/56434706/how-to-detect-tcp-keep-alive-packets-and-keep-connection-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!