即使我使用 try..except 也会出现异步套接字错误 10049
当我运行我的程序(在调试器/IDE之外)时,我收到错误异步套接字错误10049,我不应该收到消息对话框:“错误”吗?请参阅下面的代码
begin
try
ClientSocket1.open;
except
showmessage('error');
end;
end;
我做错了什么?
when ever i run my program(outside the debugger/ide) i get error asynchronous socket error 10049, am i not supposed to recieve a message dialoge : ''error''? see my code below
begin
try
ClientSocket1.open;
except
showmessage('error');
end;
end;
what am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该做的是处理 TClientSocket 的 Error 事件,因为这是您能够捕获套接字错误的地方。
ErrorCode 参数是包含 WinSock 错误代码的参数
如果你想消除错误,你可以将 ErrorCode 设置为 0,这将防止抛出异常,之后你可以识别错误是什么并按照你想要的方式处理它
我希望这对
Gaetan Siry有帮助
What you should do is handle the Error event of the TClientSocket, because that is where you will be able to capture your socket errors.
The ErrorCode parameter is the one that will have the WinSock Error code
If you want to silence the Error, you can set ErrorCode to 0, which will prevent the exception from being thrown, and after that you can identify what the error is and handle it the way you want it
I hope this helps
Gaetan Siry
TClientsocket 组件(已弃用 暂时已经)使用异步通信模型,所以有可能异常不是在Open方法中抛出而是在消息中抛出/ 接收传入数据的事件处理方法。
更新:如果我输入一个无效的 IP 地址(如 1.2.3.4),我可以使用 Delphi 6 和给定的代码重现此问题。
要修复它,我将移动到 TCP/IP 库,如 Indy 或 Ararat Synapse(两者都有通用的 TCP 客户端组件)。
The TClientsocket component (which is deprecated for a while already) uses the asynchronous communication model, so it is possible that the exception is not thrown in the Open method but in the message / event handling method which receives the incoming data.
update: I can reproduce this with Delphi 6 and the given code, if I enter an invalid IP address like 1.2.3.4
To fix it I would move to a TCP/IP library like Indy or Ararat Synapse (both have a generic TCP client component).