Thread View: borland.public.cppbuilder.internet.socket
6 messages
6 total messages
Started by Peter Nunn
Fri, 01 Sep 2006 01:15
Indy UDP in a console app.
Author: Peter Nunn
Date: Fri, 01 Sep 2006 01:15
Date: Fri, 01 Sep 2006 01:15
18 lines
1587 bytes
1587 bytes
Hi folks, I'm trying to do something that is a bit out of the norm, but I have a requirement to develop a UDP listner that can be launched by createprocess, by a service, so it needs to be in the background without a window showing. 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. Exactly the same code in an application works fine. Am I missing a process loop or something similar? I'm just running the listner in the forground as an app at the moment. The console window opens, it makes the data file, but that's it. Any clues? Am I missing the boat totally? Is there a better way? Ta. Peter.
Re: Indy UDP in a console app.
Author: Remy Lebeau (TeamB)
Date: Fri, 01 Sep 2006 08:00
Date: Fri, 01 Sep 2006 08:00
17 lines
1343 bytes
1343 bytes
"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
Re: Indy UDP in a console app.
Author: pedrooz
Date: Mon, 04 Sep 2006 00:02
Date: Mon, 04 Sep 2006 00:02
81 lines
3043 bytes
3043 bytes
Hi Remy,
thanks for the reply.
I'm using Indy 9 in BCB6 and have an IdUDPServer on a data module.
I've put the following in the UDPRead even handler...
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;
but it never gets called.
The Console app has the following main..
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;
}
die is a reference to a bool in the constructor.
Thanks agan.
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
Re: Indy UDP in a console app.
Author: pnunn
Date: Fri, 22 Sep 2006 11:15
Date: Fri, 22 Sep 2006 11:15
107 lines
3778 bytes
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
>
>
Re: Indy UDP in a console app.
Author: Bob Gonder
Date: Tue, 26 Sep 2006 13:49
Date: Tue, 26 Sep 2006 13:49
24 lines
1672 bytes
1672 bytes
pnunn wrote:
>> 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;
Did you set IdUDPServer->ThreadedEvent to true?
>> for(;;)
>> {
>> Sleep(100);
>> if(die)
>> break;
>> }
while( ! die )
Sleep(100);
But even better, especially for services, would be to use a WaitFor.
You never closed the file.
dm->file.close;
Re: Indy UDP in a console app.
Author: Peter Nunn
Date: Thu, 28 Sep 2006 23:47
Date: Thu, 28 Sep 2006 23:47
34 lines
1733 bytes
1733 bytes
Bob,
thankyou so much.. that was what was missing.
Now.. to see if I can start processes from a service and track them easily
Peter.
Bob Gonder wrote:
> pnunn wrote:
>
>>> 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;
>
> Did you set IdUDPServer->ThreadedEvent to true?
>
>>> for(;;)
>>> {
>>> Sleep(100);
>>> if(die)
>>> break;
>>> }
> while( ! die )
> Sleep(100);
>
> But even better, especially for services, would be to use a WaitFor.
>
> You never closed the file.
> dm->file.close;
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads