unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdTCPConnection, IdTCPClient, IdBaseComponent,
IdComponent, IdTCPServer;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Server: TIdTCPServer;
Client: TIdTCPClient;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure ServerExecute(AThread: TIdPeerThread);
procedure ServerConnect(AThread: TIdPeerThread);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type
TTest =
record
a, b, c: integer;
end;
var
Form1: TForm1;
Stream, stream2: TMemoryStream;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var Test: TTest;
begin
client.Connect;
Test.a := 1;
Test.b := 2;
Test.c := 3;
Stream := TMemoryStream.Create;
Stream.
Write(Test, Sizeof(Test));
Client.WriteStream(stream, true, true, 0);
end;
procedure TForm1.ServerExecute(AThread: TIdPeerThread);
begin
Label1.Caption := '
Connected';
end;
procedure TForm1.ServerConnect(AThread: TIdPeerThread);
var test2: TTest;
begin
Stream2 := TMemoryStream.Create;
athread.Connection.ReadStream(stream2);
Stream2.Position := 0;
Stream.
Read(Test2, Sizeof(TTest));
memo1.Lines.Add(inttostr(test2.a));
// wenn a oder b dann kommt eine große zahl, wenn c kommt 0
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Stream.Free;
stream2.Free;
end;
end.