Article View: borland.public.cppbuilder.internet.socket
Article #5587Re: Indy TIdTCPServer creation at untime
From: J�nior B. Dymow
Date: Fri, 16 Jul 2004 20:36
Date: Fri, 16 Jul 2004 20:36
71 lines
3541 bytes
3541 bytes
Thanks by the tips.
But as I said, the code I posted is just a test app, not my real application
(but your tips about threads are very useful). The point is: creating the
TIdTCPServer object dinamically doesn't works. When I connect a client
application, the answer I have is: "No connection could be made because the
target machine refused it (10061), on API 'connect' (I'm translating it from
my native language, but I think you'll understand it :-). When the component
is on the form (with the same port, and the same OnExecute function
assigned), it works fine.
Do you know what's happening?
Thanks,
=======================
J�nior B. Dymow
Desenvolvimento
Specto Pain�is Eletr�nicos
junior@specto.com.br
Fone / Fax: (48) 334-8064
=======================
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> escreveu na
mensagem news:40f831be$4@newsgroups.borland.com...
>
> "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:
<40f83bb1$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40f822f9@newsgroups.borland.com> <40f831be$4@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: "J�nior B. Dymow" <junior@specto.com.br> Newsgroups: borland.public.cppbuilder.internet.socket References: <40f822f9@newsgroups.borland.com> <40f831be$4@newsgroups.borland.com> Subject: Re: Indy TIdTCPServer creation at untime Date: Fri, 16 Jul 2004 17:36:32 -0300 Lines: 73 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 200.135.30.176 Message-ID: <40f83bb1$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1090010033 200.135.30.176 (16 Jul 2004 13:33:53 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail