如何完全断开TCPClient? (印地)

发布于 2024-09-15 23:15:01 字数 201 浏览 2 评论 0原文

当我的 Tcpclient 工作时,使用以下代码:

TCPClient.Disconnect;
TCPClient.Connect;

我仍然收到“引发异常类 EIdAlreadyConnected 并带有消息“已连接”。” 错误(而之前已断开连接)。

那么,我怎样才能完全断开它呢?

谢谢

When my Tcpclient is working , with this code :

TCPClient.Disconnect;
TCPClient.Connect;

I get "raised exception class EIdAlreadyConnected with message 'Already connected.'." error still (whereas , it has been disconnected before) .

So , how can i disconnect it totally ?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心头的小情儿 2024-09-22 23:15:01

在 indy 10 中使用时,您必须确保输入缓冲区为空。

if idTcpClient.connected then
begin
 idTcpClient.IOHandler.InputBuffer.clear;
 idTcpClient.Disconnect;
end;

using at indy 10 you must sure inputbuffer is empty.

if idTcpClient.connected then
begin
 idTcpClient.IOHandler.InputBuffer.clear;
 idTcpClient.Disconnect;
end;
五里雾 2024-09-22 23:15:01

你说它已断开连接,但你只给出了断开连接的命令。

网络流量需要时间,并且您可能在真正断开连接之前重新连接。

也许您需要监视某些连接状态或事件以等待真正断开连接。

...或者尝试处理异常并忽略它,使用 try..except

You say it is disconnected, but you only gave the command to disconnect.

Network traffic takes time, and probably you reconnected before you were really disconnected.

Probably you need to monitor some connection state or event to wait till you really are disconnected.

... or try to process the exception and ignore it, using try..except

我ぃ本無心為│何有愛 2024-09-22 23:15:01
TCPClient.IOHandler.InputBuffer.Clear;
TCPClient.IOHandler.CloseGracefully;
TCPClient.Disconnect;
TCPClient.IOHandler.InputBuffer.Clear;
TCPClient.IOHandler.CloseGracefully;
TCPClient.Disconnect;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文