Board index » delphi » TIdPeerThread(1).Connection.WriteLn('hi');

TIdPeerThread(1).Connection.WriteLn('hi');


2003-12-05 04:48:07 AM
delphi204
Y dos this not work?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, Sockets,
IdSocketHandle,
IdThreadMgr, IdThreadMgrDefault, StdCtrls;
type
TForm1 = class(TForm)
IdTCPServer1: TIdTCPServer;
IdThreadMgrDefault1: TIdThreadMgrDefault;
TcpClient1: TTcpClient;
Button1: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure IdTCPServer1Connect(AThread: TIdPeerThread);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
Binding : TIdSocketHandle;
begin
IdTCPServer1.Bindings.Clear;
Binding := IdTCPServer1.Bindings.Add;
Binding.IP := TcpClient1.LocalHostAddr;
Binding.Port := 10000;
IdTCPServer1.Active := true;
end;
procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
begin
AThread.Connection.WriteLn('Velkommen');
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
memo1.Lines.Add(AThread.Connection.ReadLn);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TIdPeerThread(1).Connection.WriteLn('hi');
end;
end.
 
 

Re:TIdPeerThread(1).Connection.WriteLn('hi');

"Jens" <XXXX@XXXXX.COM>writes
Quote
Binding.IP := TcpClient1.LocalHostAddr;
If you are trying to get the local IP for the machine, I'd suggest using
TIdStack::LocalAddress instead, ie:
Binding.IP := GStack.LocalAddress;
Or, just leave the IP blank to bind to all available IP addresses.
Quote
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
begin

memo1.Lines.Add(AThread.Connection.ReadLn);

end;
Do not directly access GUI components from the OnExecute event. The event
handler is triggered in the context of the specified worker thread, not the
main thread. Thus, you must use the worker thread's Synchronize() method,
or a separate TIdSync, in order to access the GUI safely.
Quote
TIdPeerThread(1).Connection.WriteLn('hi');
Assuming you are trying to send the string via the client component (why are
you using the CLX's client componet instead of Indy's?), then that should be
this instead:
TcpClient1.Sendln('hi', LF);
Gambit