unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdTCPServer, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, ComCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
Client: TIdTCPClient;
Server: TIdTCPServer;
btnConnect: TButton;
SB: TStatusBar;
btnDisConnect: TButton;
btnSendStream: TButton;
imgSource: TImage;
imgDest: TImage;
procedure btnConnectClick(Sender: TObject);
procedure ClientConnected(Sender: TObject);
procedure btnDisConnectClick(Sender: TObject);
procedure ClientDisconnected(Sender: TObject);
procedure btnSendStreamClick(Sender: TObject);
procedure ServerExecute(AThread: TIdPeerThread);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
FReceiveStream : TMemoryStream;
procedure UpdateDestImage;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnConnectClick(Sender: TObject);
begin
Client.Connect;
end;
procedure TForm1.ClientConnected(Sender: TObject);
begin
SB.SimpleText:='
Connected';
btnSendStream.Enabled:=True;
end;
procedure TForm1.btnDisConnectClick(Sender: TObject);
begin
Client.Disconnect;
end;
procedure TForm1.ClientDisconnected(Sender: TObject);
begin
SB.SimpleText:='
Disconnected';
btnSendStream.Enabled:=False;
end;
procedure TForm1.btnSendStreamClick(Sender: TObject);
var
AStream : TMemoryStream;
begin
AStream:=TMemoryStream.Create;
Try
imgSource.Picture.Bitmap.SaveToStream(AStream);
Client.WriteStream(AStream,True,True);
Finally
AStream.Free;
end;
end;
procedure TForm1.ServerExecute(AThread: TIdPeerThread);
begin
FReceiveStream.Clear;
AThread.Connection.ReadStream(FReceiveStream);
{Wenn ich mich recht erinnere wird OnExecute im Kontekt des Indy-ServerThreads
aufgerufen. Deshalb nutze ich hier Synchronize um die empfangenen Daten
an imgDest zu schicken}
ATHread.Synchronize(UpdateDestImage);
end;
procedure TForm1.UpdateDestImage;
begin
FReceiveStream.Seek(0,soFromBeginning);
imgDest.Picture.Bitmap.LoadFromStream(FReceiveStream);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FReceiveStream:=TMemoryStream.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FReceiveStream.Free;
end;
end.