您好,我已經編寫了一個客戶端服務器應用程序,用於將文件從服務器傳輸到客戶端。該代碼是在我的測試很簡單:爲什麼datasnap http比tcp/ip慢得多
服務器的代碼(這是一個可執行文件作爲服務運行或應用程序)
function TServerMethods1.DownloadFile(sFile:String; out iOut:Int64): TStream;
begin
iOut := -1;
result := TFileStream.Create(sFile, fmOpenRead or fmShareDenyNone);
iOut := result.Size;
TFileStream(Result).Seek(0, TSeekOrigin.soBeginning);
end;
客戶端代碼
procedure TForm1.DownloadFileStabiel(sSourceFile,sTargetFile:String);
var
RetStream: TStream;
fs:TFileStream;
oServerMethodsClient:TServerMethods1Client;
iOut:Int64;
begin
ClientModule1.SQLConnection1.Connected:=True;
oServerMethodsClient := nil;
try
try
oServerMethodsClient := TServerMethods1Client.Create(ClientModule1.SQLConnection1.DBXConnection, True);
RetStream := oServerMethodsClient.DownloadFile(sSourceFile,iOut);
fs := TFileStream.Create(sTargetFile, fmCreate);
fs.CopyFrom(retstream,iOut);
showmessage('Klaar');
except
on E: Exception do
begin
showmessage('Oeps download: ' + E.Message);
end;
end;
finally
ClientModule1.SQLConnection1.Connected:=False;
FreeAndNIl(fs);
FreeAndNil(oServerMethodsClient);
end;
end;
在實際應用中我做的事情有點不同,我實現了文件塊和進度條等。對於速度問題,它沒有任何區別。
在客戶端我使用一個TSQLConnection,並在服務器上是使用TDSTCPServerTransport和TDSHTTPService
當我流使用HTTP這是從來沒有速度超過1Mb/s的,當I流使用TCP/IP文件它與服務器能夠處理它的I/O速度一樣快大約30a50 Mb/s
我試過不同的服務器,我總是看到相同的速度差異因子。我嘗試了不同的操作系統,Windows Server 2003,2008,2012和Windows 7.此外,它使得在同一臺機器或不同機器上運行客戶端和服務器的不同點有所不同。
你能幫助我嗎?我打算使用https,但現在我堅持使用tcp/ip