0

Trying download file from idHTTPServer. From browser i do smth like localhost:7777/files/2019/1/7/1.php and downloading the file at last.

But when i close server in debug mode i have following error

EidClosedSocket with message "Disconnected"

How can i fix this ?

procedure TRPFiles.Download;
var
  filepath: string;
begin
  filepath := ExtractFileDir(Application.ExeName) + StringReplace(RequestInfo.URI, '/', '\', [rfReplaceAll]);
  if TFile.Exists(filepath) then
  begin
    ResponseInfo.SmartServeFile(Context, RequestInfo, filepath);
    FResponses.OK();
  end;
end;

1 Answers1

0

There is nothing to fix. This is perfectly normal behavior. When you shut down the server, it closes any client sockets that are still open, which in turn causes any subsequent I/O operations on those sockets to fail. You are seeing the exception only because you are running inside the debugger. Just ignore it and let the app process it normally. The server will handle the exception internally so it can shut down the threads that manage the client sockets that have been closed. You will not see the exception when running your app outside of the debugger.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • thanks, but what if i have highLoaded server where users will download 1000000 times / per sec., isn't it better to close connection manually when download is over, if so how whould it be closed ? – Stanislav Panteleev Jan 13 '19 at 12:00
  • @StanislavPanteleev the connections will be closed automatically at the end of each response if you set `TIdHTTPServer.KeepAlive` to false, or if you manually set `AResponseInfo.CloseConnection` to true, or if client requests ask for their connections to be closed. That is past of the HTTP protocol. But that is not what you asked about, you asked about server shutdown, which is a different issue. Unless I misread your question, it is a little ambiguous. – Remy Lebeau Jan 13 '19 at 18:07