开发者

Check if connection is Closed !

I've written a Delphi (2009) app with Indy (TCPServer/Client). And I have a problem at the level of TCPServer : it detects t开发者_StackOverflow社区he deconnection(after a reboot of the PC) of the Client only when the client tries one more time to reconnect to the server. I've executed my app step by step, and when the client tries top reconnect (after the reboot), the server raises (a silent, i think) exception : Connection reset by peer. Why this exception is too late.

(I Think the thread lister is not released immediately)

What do you think ?


This is a low-level detail of the TCP protocol. By default, it doesn't transmit keep-alive packets, because that wastes bandwidth, so it will only realise that the connection has died when something happens that prompts it to check the connection. (I'm not sure why a reconnection from the same client would trigger this though.)

You can make TCP send regular keep-alive packets to discover disconnections earlier. In windows, this can be activated by the server application, but is configured via the registry (see here for details).

You may also be able to implement a keep-alive mechanism at the protocol level by getting the client or server to send occasional null packets (a packet that does nothing in particular). This obviously requires that the protocol you are using define some kind of do-nothing or do-nothing-interesting message (NOOP, STATUS, PING ... stuff like that).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜