我在服务器那边传输的流大小是17个字节,但是在客户端那边却有85个字节,打开文件全部都是乱码来的
server:
procedure TForm1.serverExecute(AThread: TIdPeerThread);
var
intfilesize:int64;
begin
if edtpath.Text <>'' then
begin
try try
if not assigned(fs) then
begin
fs:=tfilestream.Create(edtpath.text,fmopenread);
fs.Position:=0;
showmessage(inttostr(fs.size));
end; athread.connection.WriteStream(fs,false,true,FILESIZE); if fs.Position =fs.Size then
athread.Connection.Disconnect;
except on ex:exception do
raise exception.Create(ex.Message );
end;
finally
if fs.Position =fs.Size then
fs.Free;
end;
end;
end;client:
try try
if not client.Connected then
begin
client.Host:='127.0.0.1';
client.Port:=8080;
client.Connect();
end; ms:=tmemorystream.Create;
client.readstream (ms,1,true);
showmessage(inttostr(ms.size));
ms.SaveToFile('d:\text.txt');
except on ex:exception do
raise exception.Create(ex.Message );
end;
finally
ms.Free;
end;
server:
procedure TForm1.serverExecute(AThread: TIdPeerThread);
var
intfilesize:int64;
begin
if edtpath.Text <>'' then
begin
try try
if not assigned(fs) then
begin
fs:=tfilestream.Create(edtpath.text,fmopenread);
fs.Position:=0;
showmessage(inttostr(fs.size));
end; athread.connection.WriteStream(fs,false,true,FILESIZE); if fs.Position =fs.Size then
athread.Connection.Disconnect;
except on ex:exception do
raise exception.Create(ex.Message );
end;
finally
if fs.Position =fs.Size then
fs.Free;
end;
end;
end;client:
try try
if not client.Connected then
begin
client.Host:='127.0.0.1';
client.Port:=8080;
client.Connect();
end; ms:=tmemorystream.Create;
client.readstream (ms,1,true);
showmessage(inttostr(ms.size));
ms.SaveToFile('d:\text.txt');
except on ex:exception do
raise exception.Create(ex.Message );
end;
finally
ms.Free;
end;
解决方案 »
- TComponent构造函数
- 谁能帮我把这个函数作成delphi的?
- 最小化成托盘的问题
- 我建立了一个Delphi控件制作的群,如果有兴趣可以加入进来(有空请顺手UP一下,谢过)
- 设置窗体为非激活状态
- 我用的是2000系统,最近老是弹出信使服务的窗口 ,怎么样才能拒绝这样的消息?
- 下面是"树型结构表示科目代码的一种高效算法"用BDE连接数据库的,那怎么改成ADO连接呀,答者有分
- 一个老程序员在情人节对中国软件业的致言 (看得我好郁闷) (经典)
- 关于string类型的问题:
- 如何使PageControl的某一页不可见,包括这一页的标题也不可见,PageControl1.Pages[0].visible :=false达不到我要的效果阿,怎么办呢
- 询问一个delphi7开发时遇到的错误的原因
- 如何快捷的找到源程序中的过程或函数呢?
--------------------------------
我的网站,支持一下:www.517yn.net
athread.connection.openwritebuffer;
try
athread.connection.writestream(fs); //发送流
athread.connection.closewritebuffer;
except
athread.connection.cancelwritebuffer;
end;
好象是这么做!
应该
client.readstream (ms^,1,true);