Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jul : in a TIdTCPServer, OnConnect handler not being called
| Subject: | in a TIdTCPServer, OnConnect handler not being called |
| Posted by: | "Mac" (mac_delp..@hotmail.com) |
| Date: | 4 Jul 2006 07:08:09 |
Hello,
I am trying to write a simple client/server console application
using Indy (source code for both appear below).
My problem is that my event handler for OnConnect does not appear
to be invoked, even though it appears as if the client *is*
establishing a connection. Might any of you see my error?
Regards,
Mac
// Server follows ...
program Indy_TCP_Server ;
{$APPTYPE CONSOLE}
uses
SysUtils ,
IdTCPServer ;
type
MyClass = class
procedure OnConnectEventHandler ( AThread : TIdPeerThread ) ;
end ; // MyClass
procedure MyClass.OnConnectEventHandler
( AThread : TIdPeerThread ) ;
begin
writeln ( 'Entering MyClass.OnConnectEventHandler ...' ) ;
end ; // MyClass.OnConnectEventHandler
var
myObject : MyClass ;
theTIdTCPServer : TIdTCPServer ;
begin
writeln ( 'This is the Indy_TCP_Server.' ) ;
myObject := MyClass.Create ;
theTIdTCPServer := TIdTCPServer.Create ( NIL ) ;
theTIdTCPServer.DefaultPort := 1234 ;
theTIdTCPServer.OnConnect := myObject.OnConnectEventHandler ;
writeln ( 'theTIdTCPServer.Version is ... ',
theTIdTCPServer.Version ) ; // prints 9.00.10
writeln ( 'theTIdTCPServer.Active is ... ',
theTIdTCPServer.Active ) ; // FALSE
theTIdTCPServer.Active := TRUE ;
writeln ( 'theTIdTCPServer.Active is ... ',
theTIdTCPServer.Active ) ; // TRUE
end.
// Client follows ...
program Indy_TCP_Client ;
{$APPTYPE CONSOLE}
uses
SysUtils ,
IdTCPClient ;
var
theTIdTCPClient : TIdTCPClient ;
begin
writeln ( 'This is the Indy_TCP_Client.' ) ;
theTIdTCPClient := TIdTCPClient.Create ( NIL ) ;
theTIdTCPClient.Host := '127.0.0.1' ;
theTIdTCPClient.Port := 1234 ;
theTIdTCPClient.Connect ( -1 ) ;
write ( 'theTIdTCPClient.Connected is ... ',
theTIdTCPClient.Connected ) ; // TRUE
theTIdTCPClient.Disconnect ;
end.