在局域网中,需要传递文件的名称、路径、大小、创建时间4个信息,由服务端传递至客户端;
本人考虑采用“|”进行分割,一行一组数据,传至客户端后再进行解析。用哪个组件可以实现呢?
尝试用IdTcpServer、IdTcpClient的WriteStrings、ReadStrings,但未能实现。
QQ|D:\Tencent\QQ.exe|1.42K|2010-03-22 10:20:35
Nokia PCSuit|D:\Nokia Soft\Nokia_PC_Suite_chi_sc_web.exe|33.924K|2010-05-02 12:03:11
PLSql|E:\Setup\plsqldev803|18.281K|2009-11-30 22:32:11
解决方案 »
- 关于远程注入的小问题.....最高分求答.......................................................................
- delphi的一个关于string的问题
- RichTextBox在delphi中打印的问题??????????????????????????
- 高兴!本人搜集和自写的公用函数大放送,希望对大伙有用,多多支持呵!
- 我晕,刚才还好好的,现在DELPHI一打开那个单元就自动退出,什么提示都没有啊....救我...
- 在程序运行时如何实现拖动、调整控件的大小,
- 如何發送中文字串??
- 超大整数相乘
- 这样的正则表达式要怎么写,在线等,跪求
- 在DELPHI中,用SQL语句把二进制数据插入到BLOB字段的问题!
- Inno Setup安装问题之CreateMutex
- Delphi的DataSet,DataSource,DBGrid是如何协同工作的?
你用CHAR一个字符一个字符接收吧.
var combineChar:string;
repeat
temChar:=IdTCPClient1.ReadChar(); //停顿在这一句 combineChar:=combineChar+temchar;
until temChar='';
给你两个不成熟的例子,仅作参考,高手不要拍砖啊。
基于TCP
Server端
'设定:
Bindins *.*.*.*
Defaultport 你的端口,注意不要和现在被占用的端口冲突,无论采用何种协议,端口可定义在0到65535之间。且最好不采用大于49151的动态端口。'
...
IdTCPServer1.Active:=true;
... procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var buffer:array of Byte;
i,size,fsize:integer;
filestream:Tmemorystream;
filename,filepath:string;
begin
i:=0;
fsize:=1024;
size:=athread.Connection.ReadInteger();
athread.Connection.WriteInteger(size);
filename:=athread.Connection.ReadLn();
if filename<>'no' then
begin
filestream:=tmemorystream.Create;
while i<size do
begin
athread.Connection.ReadBuffer(buffer[i],fsize);
filestream.WriteBuffer(buffer[i],fsize);
memo2.Lines.Add('开始接受数据,大小为:'+inttostr(size)+' 当前:'+inttostr(i));
RzProgressBar1.Percent:=trunc(RoundTo(i/size,-2)*100);
if(size-i)>=fsize*2 then
i:=i+fsize
else
begin
i:=i+fsize;
fsize:=(size-i);
end;
end;
memo2.Lines.Add('保存文件大小为:'+inttostr(size));
filestream.SaveToFile('E:\TCP\TCP\'+filename);
memo2.Lines.Add('保存成功!');
end;
end; Client端
'设定
boudport 和服务器端口一致
port 和服务器端口一致
host 主机IP
//连接
......
try
if not idtcpclient1.Connected then
idtcpclient1.Connect();
filestream:=tmemorystream.Create;
if opendialog1.Execute then
begin
filename:=opendialog1.FileName;
filestream.LoadFromFile(filename);
size:=filestream.Size;
idtcpclient1.Connect();
filestream.Position:=0;
idtcpclient1.WriteInteger(filestream.Size);
idtcpclient1.WriteStream(filestream,true,false);
end;
except
memo1.Lines.Add('连接失败! --->'+timetostr(now));
end;
......
//断开连接
try
if idtcpclient1.Connected then
begin
idtcpclient1.Disconnect;
end;
except
memo1.Lines.Add('断开失败! --->'+timetostr(now));
end;
......
procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var sendstr:string;begin
try
SetLength(sendstr,AData.Size);
AData.Read(sendstr[1],AData.Size);
memo1.Lines.Add(sendstr+'&'+FormatdateTime('YYYY-MM-DD hh:mm:ss',now()));
.......
end;
end;Client端
......
IdUDPClient1.Send(memo1.Text+inttostr(i)+'条---'+formatdatetime('HH:MM:SS:ZZZ',now()));
.....
i:=1024;
while i <size do
……
我的需求是,文件大小是未知的,也是无限制的。