此乃接收
procedure TServerForm.UDPServerUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
Var
Str: String;
j: Tjpegimage ;
AMem: TMemoryStream;
begin
AData.Seek(0, 0);
SetLength(Str, AData.Size);
AData.Read(Str[1], AData.Size);
if Pos('Send file:File Name:', Str)>0 then
begin
Delete(Str, 1, Length('Send file:File Name:'));
FileName := Str;
Str := 'Recived File Name OK';
ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, Str[1], Length(Str));
end else if Pos('Send File:File Length:',Str)>0 then
begin
Delete(Str, 1, Length('Send File:File Length:'));
FileSize := StrToIntDef(Str, 0);
Mem.Clear;
Mem.Position := 0;
Str:='Recived File Length OK';
ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, Str[1], Length(Str));
end else if Pos('Send File:File End',Str)>0 then
begin
if Mem<>nil then
begin
AMem := TMemoryStream.Create;
try
Mem.Position := 0;
ShowMessage(IntToStr(Mem.Size));
TCompressStream.DecompressData(Mem, AMem);
ShowMessage(IntToStr(AMem.Size));
AMem.Position := 0;
finally
FreeAndNil(AMem);
end;
Mem.Position := 0;
j := tjpegimage.Create;
try
J.LoadFromStream(Mem);
finally
Str:='Recived File OK';
ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, Str[1], Length(Str));
image1.Picture.Assign(j);
end;
end;
FileName:='';
FileSize:=0;
end else
begin
if Mem<>nil then
begin
// Mem.Seek(0, 2);
Mem.WriteBuffer(AData, AData.Size);
// Mem.Write(AData, AData.Size);
// AData.Seek(0, 0);
// Mem.CopyFrom(AData,AData.Size);
Gauge1.Progress:=Round(Mem.Size/FileSize*100);
Str:='Recived File Package OK';
ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, Str[1], Length(Str));
Application.ProcessMessages;
end;
end;
end;