Hello All,
I have the following OnGet procedure in my code:
When I open a 'client' (an html file designed to hit the address of this web server and make a GET request), I get the info I want, but when I close the browser window, I get one of two responses.
(1) No error at all.
(2) Socket Error #0
I assume that #2 is due to the fact that AResponseInfo.WriteContent; is still working just as the browser window is closing (thus closing the connection and causing an error). When the program errors out, that is the line it points to.
The oddest thing is - no matter what the exception is, I cannot catch it! My program insists on displaying an error dialog instead of whatever I have in my 'except' section. All i need to do is be able to catch that error and ignore it. What do i need to do here?
Thanks,
-Tony
I have the following OnGet procedure in my code:
Code:
procedure TWebServer.OnGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
Response: String;
MemStream: TMemoryStream;
Size: Integer;
begin
CThread.Connection.WriteLn('SEND');
Response := CThread.Connection.ReadLn;
MemStream := TMemoryStream.Create;
Size := CThread.Connection.ReadInteger;
CThread.Connection.ReadStream(MemStream,Size,False);
if not AThread.Terminated and AThread.Connection.Connected then
begin
try
AResponseInfo.ContentStream := MemStream;
AResponseInfo.WriteContent;
except
ShowMessage('Client not connected');
end;
end;
end;
When I open a 'client' (an html file designed to hit the address of this web server and make a GET request), I get the info I want, but when I close the browser window, I get one of two responses.
(1) No error at all.
(2) Socket Error #0
I assume that #2 is due to the fact that AResponseInfo.WriteContent; is still working just as the browser window is closing (thus closing the connection and causing an error). When the program errors out, that is the line it points to.
The oddest thing is - no matter what the exception is, I cannot catch it! My program insists on displaying an error dialog instead of whatever I have in my 'except' section. All i need to do is be able to catch that error and ignore it. What do i need to do here?
Thanks,
-Tony