I'l use indy components connecting client and server.
If the sever doesn't run, i get an error messgage # 10057 and after this ( in the IDE) the exception warning.
example:
try
TCPClient.Host := DefaultServerIP;
TCPClient.Port := DefaultServerPort;
TCPClient.Connect;
except
on E: Exception do MessageDlg ('Error while connecting to ScreenThiefSERVER:'+#13+E.Message, mtError, [mbOk], 0);
end;
The Client should run as hidden program and wait until the server is running.
Wo is able to help me`?
Thanks
Bert Tasler
> If the sever doesn't run, i get an error messgage
> # 10057
You should only get that error if you try to actually read or write on a
socket that is not connected. Establishing the actual connection generates
different errors if the server is not running. Please show your actual
code. It sounds like you are not handling the errors properly.
> The Client should run as hidden program and wait
> until the server is running.
Then don't call MessageDlg() in your exception handler. That is not a
hidden operation. The fact that you are catching exceptions when calling
Connect() is enough to let the program remain hidden. Whatever you are
seeing while running the program inside the IDE will not be displayed at
run-time outside of the IDE. If you don't want the exceptions to appear
during design-time, then go into the Debugger's preferences and add the
desired exceptions to the list of exceptions that the debugger ignores.
Gambit
Sorry, it was the wrong error number, its "Socket error # 10061. Connection refused.
The Mgsbox is only for testing purposes.
I'd like to repeat trying to connect a certain time invall (2..5) minutes and then halt.
Thanks for Your quick answers !
Bert Tasler
>
>
> Sorry, it was the wrong error number, its "Socket error # 10061.
Connection refused.
That error does mean that the server is not active at the time. Simply
wrapping the Connect() in a try...except block is enough to catch that
error.
> I'd like to repeat trying to connect a certain time invall (2..5) minutes
and then halt.
Simply put the Connect() into a loop, ie:
TCPClient.Host := DefaultServerIP;
TCPClient.Port := DefaultServerPort;
For I := 1 to 10 do
begin
try
TCPClient.Connect(5000);
Break;
except
Sleep(30000);
end;
end;
if TCPClient.Connected then
begin
// use the socket as needed...
end else
MessageDlg('Could not Connect after 5 minutes', mtError, [mbOk], 0);
Gambit
thanks!!
Bert Tasler