πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #5586

Re: Indy TIdTCPServer creation at untime

#5586
From: Remy Lebeau (TeamB)
Date: Fri, 16 Jul 2004 19:52
44 lines
2523 bytes
"JοΏ½nior B. Dymow" <junior@specto.com.br> wrote in message
news:40f822f9@newsgroups.borland.com...

> It works fine when I create it at designtime, but
> in runtime it doesn't receive any connection.

Please elaborate.

> I really need to use it at runtime, since may app
> runs as a service and doesn't have a form.

TService derives from TDataModule, and as such you can place the
TIdTCPServer on the service at design time just like you can with a form.

> void __fastcall TForm1::vServerSocketConnectEvent(TIdPeerThread *kpThread)
> {
>     ShowMessage("This host has been connected: " +
> kpThread->Connection->LocalName);
> }

Do not use ShowMessage() here.  It displays a VCL form, and thus is not
thread-safe.  The OnConnect event is triggered in the context of the worker
thread specified by the AThread parameter, not in the context of the main
VCL thread.  If you need to use ShowMessage(), you have to use the thread's
Synchronize() method so that the VCL form displayed will work properly.
Otherwise, use a thread-safe dialog, such as the Win32 API's MessageBox()
function instead.

Also, just an FYI, the LocalName property will display the server's name,
not the client's.  You have to look up the client's name manually:

    void __fastcall TForm1::vServerSocketConnectEvent(TIdPeerThread
*AThread)
    {
        AnsiString IP = AThread->Connection->Socket->Binding->PeerIP;
        AnsiString Host = GStack->WSGetHostByAddr(IP);
        AnsiString Msg = "This host has been connected: " + IP + ", " +
Host;
        ::MessageBox(NULL, Msg.c_str(), "Connected", MB_OK);
    }


Gambit
Technical Details
Message-ID: <40f831be$4@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40f822f9@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,245bc6439db2ac9c
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <40f822f9@newsgroups.borland.com>
Subject: Re: Indy TIdTCPServer creation at untime
Date: Fri, 16 Jul 2004 12:52:10 -0700
Lines: 46
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <40f831be$4@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1090007486 68.69.17.41 (16 Jul 2004 12:51:26 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail