mark_c wrote:I'm trying to write a program that tests a LAN and I can't continue the test because Windows system messages always appear.
I tried setting SetErrorMode (SEM_NOGPFAULTERRORBOX); but it does not work.
Of course not, because there is no system dialog
being displayed in this situation, just a VCL dialog
for a thrown exception. SetErrorMode() has no effect on that.
Change ESocketError to Exception in your catch block.
If you are still seeing the dialog, the only remaining way that can happen is if you are running your code inside the debugger, which of course will always display a thrown exception (even if it is caught later) unless you tell it not to.
solved by rewriting this event:
Code: Select all
void __fastcall TForm1 :: ClientSocket1Error (TObject * Sender,
TCustomWinSocket * Socket, TErrorEvent ErrorEvent, int & ErrorCode)
ErrorCode = 0;
this event was already set but did not want to work. I deleted and rewrote it and now it works, as if it were invisible to the compiler before the deletion.
More likely, it simply wasn't assigned to the TClientSocket::OnError event, like you thought it was.
mark_c wrote:how to synchronize connection, download and disconnection?
If I run this program, the second connection does not wait for the entire download of the first to be terminated but to interrupt it.
That is because TClientSocket runs in non-blocking mode
by default, so you need to change it to blocking mode
. And also because you are not actually implementing the HTTP protocol, otherwise you would know exactly when the 1st download is complete before then invoking the second download.
But really, why are you handling this manually at all, instead of using a pre-existing HTTP component/library instead? HTTP is not trivial to implement from scratch. There are many HTTP implementations available for C++Builder. Indy (which comes pre-installed) has a TIdHTTP client component. Other popular libraries like ICS and Synapse have their own HTTP clients, too. Or, just use Microsoft's own WinInet or WinHTTP APIs that are built into Windows itself.