是否可以立即终止 TCPClient?
我的应用程序使用 TidTCPClient 将数据发送到服务器。服务器使用 TidTCPServer。一切正常,我现在正在尝试处理意外情况。
当我断开服务器和客户端之间的网线,然后尝试关闭客户端时,它等待了很长时间,直到最终关闭:
TCPClient.IOHandler.InputBuffer.Clear;
TCPClient.Disconnect;
TCPClient.Free;
TCPClient.Free就是它等待的地方。有时是 30 秒,有时甚至更长。
有没有办法立即终止 TCPClient,无论它当时正在做什么?
My app sends data to a Server using a TidTCPClient. The Server uses a TidTCPServer. All works fine and I am now trying to handle unexpected situations.
When I disconnect the network cable between server and client, and then try to close the client, it waits for a long time, until it finally closes:
TCPClient.IOHandler.InputBuffer.Clear;
TCPClient.Disconnect;
TCPClient.Free;
TCPClient.Free is the place where it waits. This is sometimes 30 seconds, sometimes even longer.
Is there a way to terminate a TCPClient immediately, no matter what it is doing at that moment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在调用
Disconnect()
之后而不是之前清除InputBuffer
。无论如何,在断开/释放 TIdTCPClient 时,套接字没有理由导致此类挂起,除非您弄乱了套接字的 LINGER 选项。所以我首先怀疑你自己的代码有问题。您使用的是哪个版本的 Indy?您是否有分配给
TIdTCPClient
的事件处理程序?您是否尝试过在调试器中单步执行 TIdTCPClient 的析构函数以查看到底发生了什么?You should be clearing the
InputBuffer
after callingDisconnect()
, not before.In any case, there is no reason for a socket to cause such a hang when disconnecting/freeing the
TIdTCPClient
, unless you have messed around with the socket's LINGER options. So I have to suspect your own code is at fault first. Which version of Indy are you using? Do you have any event handlers assigned to theTIdTCPClient
? Have you tried stepping through TIdTCPClient's destructor in the debugger to see what is really happening?它可能会等待超时。查看组件的属性来降低超时值
It probably waits for a timeout. Look at the properties of the component to lower the timeout value