Getting asynchronous socket error 10049 even if I use try..except

when I run my program (outside the debugger / ide), I get an asynchronous socket error 10049, shouldn't I get a dialoge message: '' error ''? see my code below

begin
    try
       ClientSocket1.open;
    except
       showmessage('error');
    end;
end;

what am I doing wrong?

+3
source share
2 answers

What you need to do is handle the Error event from TClientSocket, because that is where you can fix socket errors.

ErrorCode - , WinSock Error, ErrorCode 0, , , , , .

procedure TForm1.ClientSocket1Error(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
var error : Integer; 
begin

   error := ErrorCode; {prevent exception from being thrown}

   ErrorCode := 0;

   if error = 10049 then
     showmessage('asynchronous socket error');
.
.
.


end;

,

+4

TClientsocket ( - ) , , Open, /, .

update: Delphi 6 , IP-, , 1.2.3.4

, TCP/IP, ​​ Indy Ararat Synapse ( TCP).

-1

Source: https://habr.com/ru/post/1757559/


All Articles