这是我服务器的编码
procedure TForm1.IdTCPServerExecute(AThread: TIdPeerThread);
var
InputString: string;
ACommand: string[1];
AFileName: string;
ATempFileName: string;
AFileStream: TFileStream;
begin
InputString := UpperCase(AThread.Connection.ReadLn);
ACommand := Copy(InputString, 1, 1);
AFileName := FPicFilePath + Copy(InputString, 2, 5) + '.jpg';
if ACommand = 'R' then begin
AFileStream := TFileStream.Create(AFileName, fmOpenRead + fmShareDenyNone);
try
AThread.Connection.WriteStream(AFileStream, true, true);
finally
AFileStream.Free;
end;
end else if ACommand = 'S' then begin
ATempFileName := FPicFilePath + 'TEMP.jpg';
if FileExists(ATempFileName) then
DeleteFile(ATempFileName);
AFileStream := TFileStream.Create(ATempFileName, fmCreate);
try
AThread.Connection.ReadStream(AFileStream, -1, false);
//RenameFile(ATempFileName, AFileName);
finally
AFileStream.Free;
end;
end;
AThread.Connection.Disconnect;
end;
这是我客户的编码
procedure TForm1.SendImageToServer(ASendCmd: string);
var
AFileStream: TFileStream;
begin
MessageDlg('Sending ' + ASendCmd + ' :' + FSendFileName, mtInformation, [mbOK], 0);
Screen.Cursor := crHourGlass;
with IdTCPClient do begin
if Connected then Disconnect;
Host := '127.0.0.1';
Port := 2108;
AFileStream := TFileStream.Create(FSendFileName, fmOpenRead);
try
try
Connect;
try
WriteLn(ASendCmd);
WriteStream(AFileStream, true, false);
finally
Disconnect;
end;
finally
AFileStream.Free;
end;
except
end;
end;
Screen.Cursor := crDefault;
end;
我可以成功地从服务器获取图像,但是当我必须将新图像发送回服务器时,我只有一个空的 TEMP.jpg。
请帮忙。谢谢。
德尔福 5,印地 9