Registriert seit: 8. Jun 2009
Ort: Bayern
1.138 Beiträge
Delphi 11 Alexandria
|
AW: Indy 10 / streams via tcp ip senden
23. Nov 2011, 22:04
Danke für die Antwort, Du verwendest "sockets2 und nicht den IOhandler warum ?
Delphi-Quellcode:
procedure TForm15.Button1Click(Sender: TObject);
var
ms : TMemoryStream;
g : TGraphic;
begin
if not IdTCPClient1.Connected then
IdTCPClient1.Connect;
ms := TMemoryStream.Create;
g := TGraphic(Image1.Picture.Graphic.ClassType.Create);
try
Image1.Picture.Graphic.SaveToStream(ms);
ms.Seek(0,soFromBeginning);
IdTCPClient1.Socket.Write(ms, ms.Size, true);
ms.Clear;
IdTCPClient1.Socket.ReadStream(ms, IdTCPClient1.Socket.ReadLongInt);
ms.Seek(0, soFromBeginning);
g.LoadFromStream(ms);
Image2.Picture.Graphic := g;
finally
ms.Free;
g.Free;
end;
end;
procedure TForm15.IdTCPServer1Connect(AContext: TIdContext);
begin
AContext.Connection.Socket.ReadTimeout := 50;
end;
procedure TForm15.IdTCPServer1Execute(AContext: TIdContext);
var
ms : TMemoryStream;
begin
ms := TMemoryStream.Create;
try
try
AContext.Connection.Socket.ReadStream (ms, AContext.Connection.Socket.ReadLongInt);
except
on E: EIdReadTimeout do begin end;
end;
if ms.Size > 0 then
begin
ms.Seek(0, soFromBeginning);
AContext.Connection.Socket.Write(ms, ms.Size, true);
end;
finally
ms.Free;
end;
end;
|
|
Zitat
|