Y
YuYu200508
Unregistered / Unconfirmed
GUEST, unregistred user!
错误描述:上传的文件的头几个字节被修改,如果上传的是文本文件,头几个字符被改为怪异字符。
源码如下:
客户端,发送文件
procedure Send;
var
FileStream: TFileStream;
begin
// IdTCPClient1.Connect();
FileStream := TFileStream.Create(Edit3.Text,fmOpenRead );
try
IdTCPClient1.OpenWriteBuffer();
//FileStream.Position := 0;
IdTCPClient1.WriteStream(FileStream, True, True);
IdTCPClient1.CloseWriteBuffer();
finally
FileStream.Free;
end;
IdTCPClient1.Disconnect;
end;
服务器段,接受文件
procedure TFormMain.IdTCPServer1Execute(AThread: TIdPeerThread);
var
ThisCon: TIdTCPServerConnection;
//cmd: string;
FileStream: TFileStream;
begin
ThisCon := AThread.Connection;
begin
FileStream := TFileStream.Create(Edit2.Text, fmCreate);
try
//FileStream.Position := 0;
ThisCon.ReadStream(FileStream, -1 , True);
finally
FileStream.Free;
end;
end;
end;
源码如下:
客户端,发送文件
procedure Send;
var
FileStream: TFileStream;
begin
// IdTCPClient1.Connect();
FileStream := TFileStream.Create(Edit3.Text,fmOpenRead );
try
IdTCPClient1.OpenWriteBuffer();
//FileStream.Position := 0;
IdTCPClient1.WriteStream(FileStream, True, True);
IdTCPClient1.CloseWriteBuffer();
finally
FileStream.Free;
end;
IdTCPClient1.Disconnect;
end;
服务器段,接受文件
procedure TFormMain.IdTCPServer1Execute(AThread: TIdPeerThread);
var
ThisCon: TIdTCPServerConnection;
//cmd: string;
FileStream: TFileStream;
begin
ThisCon := AThread.Connection;
begin
FileStream := TFileStream.Create(Edit2.Text, fmCreate);
try
//FileStream.Position := 0;
ThisCon.ReadStream(FileStream, -1 , True);
finally
FileStream.Free;
end;
end;
end;