终止来自 TIdTCPServer 的非活动套接字连接
我们有一个应用程序,它使用 Delphi 2007 附带的 Indy 10.1.1 组件来侦听传入的 TCP 请求。
有时,我们会收到并非来自客户端应用程序的传入连接。通常,会发生以下两种情况之一:1) 在接收到任何数据之前,连接被客户端终止,或者 2) 收到我们不期望的数据,并且我们手动终止连接。
但是,我们收到的连接没有收到任何数据,并且似乎一直持续到客户端从其一端终止连接为止。
如果在指定时间后没有收到数据,是否有办法终止与服务器的此类连接?
We have an application which listens for incoming TCP requests using the Indy 10.1.1 components that ship with Delphi 2007.
Occassionally we receive incoming connections which are not from our client application. Typically, one of two things happens: 1) the connection is terminated by the client before any data is received, or 2) data is received which we're not expecting and we manually terminate the connection.
However, we've received connections where no data is received and appear to persist until the client terminates the connection from their end.
Is there a way to terminate such a connection from the server if no data is received after a specified amount of time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 OnExecute 事件处理程序中,跟踪从客户端接收到最后一次有效数据的时间。使用连接的 ReadTimeout 属性,您可以定期使挂起的读取操作超时,以便您可以检查客户端是否有一段时间没有发送数据,如果是,则断开连接。
In your OnExecute event handler, keep track of when the last good data was received from the client. Using the connection's ReadTimeout property, you can timeout pending read operations periodically so you can check if the client has not sent data for awhile, and if so then disconnect it.
将其保存为killthread.pas
然后在服务器端执行此操作:
Save this as killthread.pas
Then do this on the server side:
我有类似的问题,我用的是delphi7+Indy9。
和我的解决方案:
在 TIdTCPServer 事件 onConnect 中,我确实喜欢这个,
也许在 Indy10 上你可以做类似的事情
i have similiar problem, i used delphi7+Indy9.
and my solution:
in TIdTCPServer event onConnect, i do like this
maybe on Indy10 you can do similiar like that
您应该能够调用
(TIdTCPConnection).Disconnect
。You should be able to call
(TIdTCPConnection).Disconnect
.