0

我正在开发一个项目,该服务器使用 C 需要向客户端发送心跳以检查其状态(使用 tcp 套接字),我想知道服务器端程序如何检测客户端是否崩溃。

确切地说,建立了tcp连接后,当服务器向客户端发送一个段时,它需要得到一个ack回复,如果客户端崩溃了,一遍又一遍地重新传输这个段怎么办?我该如何处理这种情况,谁能给我一个例子?

谢谢。

4

1 回答 1

0

When you design the protocol you are going to use in your project, you may do this any way you please. Generally, one side sends a message to the other every X seconds and the other side sends a reply. If the side that doesn't send the message doesn't receive a message in Y seconds (where Y is greater than X) it assumes the connection is dead.

Basically, you can do this any way you want if you are designing the protocol that goes on top of TCP. Just remember that TCP doesn't do this for you.

于 2012-08-21T06:44:03.497 回答