Thread View: borland.public.cppbuilder.internet.socket
9 messages
9 total messages
Started by Paul at NCF
Tue, 01 Aug 2006 07:18
Indy 9 - UDP Server and Client
Author: Paul at NCF
Date: Tue, 01 Aug 2006 07:18
Date: Tue, 01 Aug 2006 07:18
19 lines
1727 bytes
1727 bytes
Hi, I've got back on to trying out some of the Indy components to prototype some ideas for a new project, and I've come across something strange. I'm using TIdUDPClient and TIdUDPServer components in threads, both instantiated in their appropriate threads. The transmissions and data received processing is handled in the threads, with no interaction with the GUI. My test program allows the application to start as server or client, and I run the application twice, selecting server or client. This seems to cause a problem, they freeeze during the run and one hangs when closing. If I create another application with the server and client (using the same threads from the other app), and start both applications with client or server as appropriate, all seems to be fine. No freezes or hangs. Am I missing something? Is there something easy to explain this? Paul
Re: Indy 9 - UDP Server and Client
Author: Remy Lebeau (TeamB)
Date: Tue, 01 Aug 2006 20:10
Date: Tue, 01 Aug 2006 20:10
22 lines
1642 bytes
1642 bytes
"Paul at NCF" <not plmacca@clara.co.uk> wrote in message news:44cf0014@newsgroups.borland.com... > I'm using TIdUDPClient and TIdUDPServer components in threads, > both instantiated in their appropriate threads. The transmissions and > data received processing is handled in the threads, with no interaction > with the GUI. Did you set the TIdUDPServer's ThreadedEvent property to True? If not, then the OnUDPRead event handler is executed in the context of the main thread. > My test program allows the application to start as server or client, and I > run the application twice, selecting server or client. This seems to cause > a problem, they freeeze during the run and one hangs when closing. Then you are likely not managing them properly. Please show your actual code. Gambit
Re: Indy 9 - UDP Server and Client
Author: Paul at NCF
Date: Wed, 02 Aug 2006 21:40
Date: Wed, 02 Aug 2006 21:40
96 lines
3869 bytes
3869 bytes
> Did you set the TIdUDPServer's ThreadedEvent property to True? If not,
> then
> the OnUDPRead event handler is executed in the context of the main thread.
yes
> Then you are likely not managing them properly. Please show your actual
> code.
probably, what I don't understand yet is why:
- app1-server talks ok to app2-client and vv.
- app2-server to app2-client seems ok
- app1-server to app1-client doesn't
The two instances of app1 seem to lock eachother out, as in only one side
seems to run at a time. Its very strange and I'm sure there it is something
stupid that I have done. I'm trying to strip down the application and build
it up again, and when I get to a dead end I'll try to supply some code
snippets.
Basically I have a server thread and client thread, with an input Q which
signals the client thread when something is in the Q to send. The server
creates the UDP server like this, and the onread event follows:
// create client UDP component, set remote connection settings
IdUDPServer = new TIdUDPServer(NULL);
IdUDPServer->ThreadedEvent = true;
IdUDPServer->OnUDPRead = IdUDPServerUDPRead;
IdUDPServer->DefaultPort = host_port;
....
void __fastcall CUDPServerTask::IdUDPServerUDPRead(TObject *Sender,TStream
*AData,TIdSocketHandle *ABinding)
{
try
{
int BufSize = AData->Size;
int BufIndx = 0;
char * Buf = new char[BufSize];
bool result = false;
while (BufSize > 0)
{
int iRead = AData->Read( &Buf[BufIndx], BufSize );
if( iRead > 0 )
{
// success
BufIndx += iRead;
BufSize -= iRead;
result = true;
}
else
{
// fail
BufSize = 0;
}
}
// if bytes to read, and all collected
if (result)
{
// On read - process data
}
// delete buf
delete [] Buf;
}
catch(const Exception &)
{
;
}
}
The client thread has this:
// create client UDP component, set remote connection settings
IdUDPClient = new TIdUDPClient(NULL);
IdUDPClient->Host = host_name;
IdUDPClient->Port = host_port;
IdUDPClient->ReceiveTimeout = 100;
....
try
{
Trace( true, "CUDPClientTask::About to send\r\n" );
IdUDPClient->SendBuffer( ptr->Udata, ptr->Ulength );
Trace( true, "CUDPClientTask::Msg sent - On
Write\r\n" );
}
catch (...)
{
Trace( true, "CUDPClientTask::Send Exception
Raised\r\n" );
}
Re: Indy 9 - UDP Server and Client
Author: Remy Lebeau (TeamB)
Date: Wed, 02 Aug 2006 22:21
Date: Wed, 02 Aug 2006 22:21
21 lines
1694 bytes
1694 bytes
"Paul at NCF" <not plmacca@clara.co.uk> wrote in message news:44d11bab@newsgroups.borland.com... > what I don't understand yet is why: > - app1-server talks ok to app2-client and vv. > - app2-server to app2-client seems ok > - app1-server to app1-client doesn't Please provide more details about the actual setup of each one. What IP/Port values are the servers listening on? Which IP/Port values are the clients trying to send data to? > IdUDPServer->DefaultPort = host_port; You are not specifying any items for the Bindings property, so the server is going to bind to all available IP addresses by default. Is it possible that your server and client are trying to use the same IP/Port values? Gambit
Re: Indy 9 - UDP Server and Client
Author: Paul at NCF
Date: Thu, 03 Aug 2006 06:13
Date: Thu, 03 Aug 2006 06:13
18 lines
1776 bytes
1776 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:44d125a5$1@newsgroups.borland.com... > > You are not specifying any items for the Bindings property, so the server > is > going to bind to all available IP addresses by default. Is it possible > that > your server and client are trying to use the same IP/Port values? Can you give me an idea of how this is supposed to be set up, I saw these properties but didn't think I needed to set them up. I've initially set the server port to 21000, and the client properties to 127.0.0.1 and 21000 (as I'm running both sides on the same box at the moment). Can the server be setup to listen on 21000, but connect on say 21001 to 21099? Everyday is a learning experience! Paul
Re: Indy 9 - UDP Server and Client
Author: Paul at NCF
Date: Thu, 03 Aug 2006 07:37
Date: Thu, 03 Aug 2006 07:37
41 lines
2416 bytes
2416 bytes
Hi, It appears something has gone badly wrong with my framework, it doesn't seem to be anything to do with UDP or Indy components. I've run my framework test harness, and again with two instances running, it locks up and hangs. It never use to do this. Time to get my backups out of SCM and find out whats changed. I might do the same test on another machine and make sure its not my BCB install thats at fault too. I'll move on to another news group if I get stuck. Paul "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:44d125a5$1@newsgroups.borland.com... > > "Paul at NCF" <not plmacca@clara.co.uk> wrote in message > news:44d11bab@newsgroups.borland.com... > >> what I don't understand yet is why: >> - app1-server talks ok to app2-client and vv. >> - app2-server to app2-client seems ok >> - app1-server to app1-client doesn't > > Please provide more details about the actual setup of each one. What > IP/Port values are the servers listening on? Which IP/Port values are the > clients trying to send data to? > >> IdUDPServer->DefaultPort = host_port; > > You are not specifying any items for the Bindings property, so the server > is > going to bind to all available IP addresses by default. Is it possible > that > your server and client are trying to use the same IP/Port values? > > > Gambit > >
Re: Indy 9 - UDP Server and Client
Author: Paul at NCF
Date: Fri, 04 Aug 2006 21:44
Date: Fri, 04 Aug 2006 21:44
31 lines
2264 bytes
2264 bytes
This was my problem, named objects:
// create event and store handle
MyEvent = new TEvent ( NULL, false, false, MyName );
I've changed it to:
// create event and store handle
MyEvent = new TEvent ( NULL, false, false, "" );
This is why running the application twice caused problems, as signaling in
one app was causing the threads in both apps to wake up (when one wasn't
supposed to). I hope this is correct?
Is there an easy way to have named objects which are unique, such as using
the process ID? Is there an impact to the OS in having too many? (wrong
forum I know).
Paul
"Paul at NCF" <not plmacca@clara.co.uk> wrote in message
news:44d1a7a0$1@newsgroups.borland.com...
> Hi,
>
> It appears something has gone badly wrong with my framework, it doesn't
> seem to be anything to do with UDP or Indy components. I've run my
> framework test harness, and again with two instances running, it locks up
> and hangs. It never use to do this. Time to get my backups out of SCM and
> find out whats changed. I might do the same test on another machine and
> make sure its not my BCB install thats at fault too.
Re: Indy 9 - UDP Server and Client
Author: Remy Lebeau (TeamB)
Date: Fri, 04 Aug 2006 23:07
Date: Fri, 04 Aug 2006 23:07
20 lines
1718 bytes
1718 bytes
"Paul at NCF" <not plmacca@clara.co.uk> wrote in message
news:44d3bfa4$1@newsgroups.borland.com...
> This is why running the application twice caused problems, as signaling
> in one app was causing the threads in both apps to wake up (when one
> wasn't supposed to). I hope this is correct?
Yes, it is. Named objects can span across process boundaries.
> Is there an easy way to have named objects which are unique, such as
> using the process ID?
Yes. Simply append the unique ID to your non-unique name, ie:
MyEvent = new TEvent ( NULL, false, false, MyName +
IntToStr(GetCurrentProcessID) );
Gambit
Re: Indy 9 - UDP Server and Client
Author: Paul at NCF
Date: Sat, 05 Aug 2006 07:39
Date: Sat, 05 Aug 2006 07:39
4 lines
1342 bytes
1342 bytes
Thanks. I can get back to my orignal task now. > MyEvent = new TEvent ( NULL, false, false, MyName + > IntToStr(GetCurrentProcessID) );
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