【发布时间】:2015-02-09 08:01:03
【问题描述】:
您好,我已经编写了一个客户端服务器应用程序来将文件从服务器流式传输到客户端。该代码在我的测试中非常基本:
服务器代码(它是作为服务或应用程序运行的可执行文件)
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,而当我使用 tcp/ip 流式传输时,它的速度与服务器可以处理它的 i/o 一样快,大约 30a50 Mb/s
我尝试了不同的服务器,但总是看到相同的速度差异因素。我尝试了不同的操作系统,windows server 2003、2008、2012、windows 7。在同一台机器或不同机器上运行客户端和服务器也没有什么区别。
你能帮帮我吗?我原本打算使用 https,但现在我卡在 tcp/ip
【问题讨论】:
标签: client-server performance-testing delphi-xe5 datasnap