IdTCPServer在OnExecute中传输文件;
IdTcpClient有一个接受文件事件;测试中传输的文件比较大,在传输的过程中我取消掉了(类似断线之类),TCPServer却一直还在发送,请问有Server如何来设置一个中断时间,超过这个时间就让连接断开(我知道在Client可以设置,即在IdTcpClient.OnWork事件中获取到传输时间);我发现IdTcpServer死掉后,其他客户端就不能连接了,这个后果很严重,请教各位朋友怎样才能消除这样的异常!附:系统Indy版本为10.2.3,另外添加了一个TIdSchedulerOfThreadPool线程池控件。
IdTcpClient有一个接受文件事件;测试中传输的文件比较大,在传输的过程中我取消掉了(类似断线之类),TCPServer却一直还在发送,请问有Server如何来设置一个中断时间,超过这个时间就让连接断开(我知道在Client可以设置,即在IdTcpClient.OnWork事件中获取到传输时间);我发现IdTcpServer死掉后,其他客户端就不能连接了,这个后果很严重,请教各位朋友怎样才能消除这样的异常!附:系统Indy版本为10.2.3,另外添加了一个TIdSchedulerOfThreadPool线程池控件。
解决方案 »
- 送分100分:VC6与DELPHI6几个类型的对应关系[问题点数:100分]
- 怎么判断一个字符串是纯数字,怎么判断有汉字,还有英文字母
- DOC、RTF或者html文档怎么存入数据库中?
- 请问怎样对数据进行双字操作
- delphi的MDI窗体菜单,工具条融合的问题?
- 数据库的包传送问题(数据导入导出):各位给点意见和思路,高分相谢,言者有分。
- 新手一个星期来的问题!
- 怎么自定义函数???????
- 如何发消息,不使用pastfromclipboard方法,向一个memo中粘贴文本?
- 在删除目录中TSHFileOpStruct该如何定义或者声明?
- delphi 连接 Bde 问题
- 调用存储过程时出现的问题
别的线程应该不受影响啊
不知道是用的问题,还是控件本身的问题
所以,还是直接使用api的c/c++写服务程序更可控
文件大的话最好用FTP
如果用IdFtpServer 官方上有例子的
【服务器】
服务器端有IdTcpServer,IdSchedulerOfThreadPool和IdAntiFreeze,其中IdSchedulerOfThreadPool.MaxThreads设置为50
程序:
procedure TCPServerExecute(AContext: TIdContext);
var
RcvStr: String;
AFileStream: TFileStream;
begin
try
try
if (AContext.Connection.Connected) then
begin
RcvStr := AContext.Connection.IOHandler.ReadLn;
AFileName := ExtractFilePath(ParamStr(0)) + 'test.exe';
if SameText(RcvStr, 'File-') and FileExists(AFileName) then
begin
AFileStream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyWrite);
try
AContext.Connection.IOHandler.WriteLn(IntToStr(AFileStream.Size));
RcvStr := AContext.Connection.IOHandler.ReadLn;
if SameText(RcvStr, '-Ready') then
begin
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.Write(AFileStream, AFileStream.Size);
end;
if AContext.Connection.IOHandler.InputBuffer.Size >0 then
AContext.Connection.IOHandler.InputBuffer.Clear;
finally
FreeAndNil(AFileStream);
end;
end;
except
//
end;
finally
if AContext.Connection.Connected then
begin
AContext.Connection.IOHandler.CloseGracefully;
AContext.Connection.Disconnect;
end;
LeaveCriticalSection(_TSection);
end;
end;【客户端】
客户端有一个IdTcpClient,IdAntiFreeze
程序:
function TFrmMain.DownloadFile: Boolean;
var
SendStr, RcvStr: String;
Size: Int64;
AFileName: String;
AFileStream: TFileStream;
begin
Result := True;
try
try
TCPClient.Host := '127.0.0.1';
TCPClient.Port := 6000;
if not TCPClient.Connected then
TCPClient.Connect; SendStr := 'File-';
TCPClient.IOHandler.WriteLn(SendStr);
RcvStr := TCPClient.IOHandler.ReadLn;
Size := StrToInt64Def(RcvStr, 0);
if Size >0 then
begin
TCPClient.IOHandler.WriteLn('-Ready');
AFileName := 'd:\test.exe';
AFileStream := TFileStream.Create(AFileName, fmCreate);
try
TCPClient.IOHandler.LargeStream := True;
TCPClient.IOHandler.ReadStream(AFileStream, Size);
finally
FreeAndNil(AFileStream);
end;
end; if TCPClient.IOHandler.InputBuffer.Size >0 then
TCPClient.IOHandler.InputBuffer.Clear;
except
on E: Exception do
begin
Result := False;
end;
end;
finally
if TCPClient.Connected then
begin
TCPClient.IOHandler.CloseGracefully;
TCPClient.Disconnect;
end;
end;
end;
顶一下,别沉下去!
结贴了。