unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ScktComp,Dialogs,
StdCtrls;
type
CustomRec =
record
StartTag: integer;
MSG_1:
String;
MSG_2:
String;
CheckSum: Integer;
EndTag: integer;
end;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
Client: TClientSocket;
Server: TServerSocket;
ReceiveRec: CustomRec;
SendRec: CustomRec;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Client:=TClientSocket.Create(Form1);
Server:=TServerSocket.Create(Form1);
Server.OnClientRead:=ServerClientRead;
Server.Port:=10024;
Client.Port:=10024;
Client.Host:='
127.0.0.1';
Server.Open;
Client.Open;
end;
procedure TForm1.ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
Server.Socket.ReceiveBuf(ReceiveRec,sizeof(ReceiveRec));
showMessage(ReceiveRec.MSG_1);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
sendRec.MSG_1:='
Test123';
Client.Socket.SendBuf(sendRec,sizeof(sendRec));
end;
end.