unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
TForm1 =
class(TForm)
Memo1: TMemo;
Memo2: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ReceiveServer(Sender: TObject; Socket: TCustomWinSocket);
procedure ReceiveClient(Sender: TObject; Socket: TCustomWinSocket);
procedure Connect(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private declarations }
myServer: TServerSocket;
myClient: TClientSocket;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Connect(Sender: TObject; Socket: TCustomWinSocket);
begin
myClient.Active := true;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.Clear;
Memo2.Clear;
myServer := TServerSocket.Create(Self);
myServer.Port := xxxx;
myServer.Active := true;
myServer.OnClientRead := ReceiveServer;
myServer.OnClientConnect := Connect;
myClient := TClientSocket.Create(Self);
myClient.Port := xxxx;
myClient.Host := xxxx;
myClient.OnRead := ReceiveClient;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
myServer.Free;
myClient.Free;
end;
procedure TForm1.ReceiveClient(Sender: TObject; Socket: TCustomWinSocket);
var
s:
String;
begin
s := Socket.ReceiveText;
Memo2.Lines.Add(s);
myServer.Socket.Connections[0].SendText(s);
end;
procedure TForm1.ReceiveServer(Sender: TObject; Socket: TCustomWinSocket);
var
s:
String;
begin
s := Socket.ReceiveText;
Memo1.Lines.Add(s);
myClient.Socket.SendText(s);
end;
end.