Error: fStream := TFileStream.Create('tt.txt',fmOpenWrite or fmShareDenyNone);
Corret: fStream := TFileStream.Create('tt.txt',fmOpenRead or fmShareDenyWrite);
..........Server
procedure TFormServer.TCPServerExecute(AThread: TIdPeerThread);
var
SComand: String;
FStream: TfileStream;
begin
try
SComand := AThread.Connection.ReadLn;
if SComand = 'TT' then
begin
FStream := TFileStream.Create('c:\tt.txt',fmOpenRead or fmShareDenyNone);
AThread.Connection.OpenWriteBuffer;
AThread.Connection.WriteStream(FStream);
AThread.Connection.CloseWriteBuffer;
FStream.Free;
end;
finally
AThread.Connection.Disconnect;
end;
end;
..............Client
procedure TFormClient.ButtonSendClick(Sender: TObject);
var
FStream: TFileStream;
begin
TCPClient.Connect;
FStream := TFileStream.Create('c:\test.txt',fmCreate);
while TCPClient.Connected do
begin
try
TCPClient.WriteLn('TT');
TCPClient.ReadStream(FStream, -1, True);
FStream.Seek(0, soFromBeginning);
finally
TCPClient.Disconnect;
FStream.Free;
end;
end;
end;
小问题,该自己认真检查嘛
老冯一点还在抢分 佩服~~~