Okay fandt ud af at jeg kunne slå Commandhandlers fra via af kode.
Men det virker stadig ikke og jeg er ved at være godt frustreret nu! For kan simpelthen ikke finde grunden! Så håber der er en derude der kan hjælpe mig.
Her er hele uniten for serveren:
unit receiver;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdTCPServer, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Client1: TIdTCPClient;
Server1: TIdTCPServer;
Image2: TImage;
Image1: TImage;
Button1: TButton;
Edit1: TEdit;
Connect: TGroupBox;
Memo1: TMemo;
Connections: TListBox;
Label1: TLabel;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ConnectionsDblClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Server1Execute(AThread: TIdPeerThread);
procedure Server1Connect(AThread: TIdPeerThread);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Server1.CommandHandlersEnabled:= False;
Server1.Active:= True;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Server1.Active:= False;
end;
procedure TForm1.ConnectionsDblClick(Sender: TObject);
begin
Edit1.Text:= Connections.Items.Strings[Connections.Itemindex];
Button1.Click;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Client1.Disconnect;
Client1.Host:= Edit1.Text;
Client1.Connect;
Client1.WriteLn('hej');
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (Client1.Connected = true) and (Server1.Active = True) then
begin
Image1.Hide;
Image2.Show;
end
else
begin
Image1.Show;
Image2.Hide;
end;
end;
procedure TForm1.Server1Execute(AThread: TIdPeerThread);
begin
Memo1.Lines.Add(Client1.ReadLn());
end;
procedure TForm1.Server1Connect(AThread: TIdPeerThread);
begin
Connections.Items.Add(AThread.Connection.Socket.Binding.PeerIP);
end;
end.
og hele uniten for clienten:
unit sender;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdTCPServer, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient;
type
TForm1 = class(TForm)
Client1: TIdTCPClient;
Server1: TIdTCPServer;
procedure Server1Connect(AThread: TIdPeerThread);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Server1Execute(AThread: TIdPeerThread);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Server1Connect(AThread: TIdPeerThread);
begin
Client1.Disconnect;
Client1.Host:= AThread.Connection.Socket.Binding.PeerIP;
Client1.Connect;
Client1.WriteLn('hej');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Server1.CommandHandlersEnabled:= False;
Server1.Active:= True;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Server1.Active:= False;
end;
procedure TForm1.Server1Execute(AThread: TIdPeerThread);
begin
if Client1.ReadLn() = 'hej' then Client1.WriteLn('hej');
end;
end.
På forhånd tak
Mvh.
Rune Jensen
---------------------------------------------------------------------------
##The one who laugh last is the one who think slowest!##
---------------------------------------------------------------------------