🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Indy UDP in a console app.

#1967
From: pnunn
Date: Fri, 22 Sep 2006 11:15
107 lines
3778 bytes
Remy,

thankyou for this reply, I'm finally back to this (got to love managing 
developers... sigh).

The code I have is as follows...

In the console app..

> ofstream res_file;
> 
> //void __fastcall TimerHandler(TObject *Sender);
> //---------------------------------------------------------------------------
> 
> #pragma argsused
> int main(int argc, char* argv[])
> {
>   // parse environment variables to get file name
>   if(argc < 3)
>   {
>     // something went wrong, no file handle here
>     ofstream out("err_log.txt");
>     out << "Didn't get enough command line parameters" << endl;
>     return 1;
>   }
> 
>   bool die = false;
> 
>   // create data module.
>   THiddenDataModule* dm = new THiddenDataModule(NULL, argv[1], die);
>   dm->file.open(argv[1]);
>   dm->IdUDPServer->Active = false;
>   //dm->IdUDPServer->DefaultPort = argv[2];
>   dm->IdUDPServer->DefaultPort = 4000;
>   dm->IdUDPServer->Active = true;
> 
>   // loop
>   for(;;)
>   {
>     Sleep(100);
>     if(die)
>       break;
>   }
> 
>   return 0;
> }

and in the data module at event handler of
> void __fastcall THiddenDataModule::IdUDPServerUDPRead(TObject *Sender,
>       TStream *AData, TIdSocketHandle *ABinding)
> {
>   char *lpszResult = new char[AData->Size + 1];
> 
>   AData->ReadBuffer(lpszResult, AData->Size);
>   lpszResult[AData->Size] = 0;
>   file << lpszResult << endl;
>   if(strcmp("die", lpszResult) == 0)
>   {
>     m_die = true;
>   }
> 
>   delete lpszResult;
> }

When I run the client with the parameters of file.txt 400 and try and 
send packages to it, the event handler never gets called.

The same code in a window application works fine.

My reason for doing this (if it helps) is to try and decide if I should 
be using stand alone procedures started from a service to do some work 
for me, or just threads launched by the service (which is how its being 
done now).

I want to see if I can make a console app handle udp messages, and then 
I'll try launching it from a service.

Hope that all makes sense.

Hope someone can help me out here.

Ta.

Peter.




Remy Lebeau (TeamB) wrote:
> "Peter Nunn" <pnunn@infotetq.com.au> wrote in message
> news:44f789ba$1@newsgroups.borland.com...
> 
>> I've put together a console app with an attached data module
>> following some advice I found searching on here, but for some
>> reason the UDP control never gets a message it seems.
> 
> Which component(s) are you using exactly?  What does your actual code look
> like?
> 
>> Am I missing a process loop or something similar?
> 
> Maybe, but it is dificult to say for sure until you provide more details.
> 
> 
> Gambit
> 
> 
Technical Details
Message-ID: <4513c5be@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!feed.xsnews.nl!feeder.xsnews.nl!feeder.news-service.com!newsfeed.freenet.de!news.albasani.net!reader.uucp.at!feeder02.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail
References: <44f789ba$1@newsgroups.borland.com> <44f7e8f1$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,b3954c31c7b052bb
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Fri, 22 Sep 2006 21:15:15 +1000
From: pnunn <pnunn@infoteq.com.au>
User-Agent: Thunderbird 1.5.0.7 (Windows/20060909)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: Indy UDP in a console app.
References: <44f789ba$1@newsgroups.borland.com> <44f7e8f1$1@newsgroups.borland.com>
In-Reply-To: <44f7e8f1$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 203.51.160.32
Message-ID: <4513c5be@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1158923710 203.51.160.32 (22 Sep 2006 04:15:10 -0700)
Lines: 107
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!feed.xsnews.nl!feeder.xsnews.nl!feeder.news-service.com!newsfeed.freenet.de!news.albasani.net!reader.uucp.at!feeder02.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail