Article View: borland.public.cppbuilder.internet.socket
Article #2160Re: Indy 9 - UDP Server and Client
From: 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" );
}
Technical Details
Message-ID:
<44d11bab@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!newsfeed0.kamp.net!newsfeed.kamp.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<44cf0014@newsgroups.borland.com> <44cfb716$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,30a8f8e1a1549b1e X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Paul at NCF" <not plmacca@clara.co.uk> Newsgroups: borland.public.cppbuilder.internet.socket References: <44cf0014@newsgroups.borland.com> <44cfb716$1@newsgroups.borland.com> Subject: Re: Indy 9 - UDP Server and Client Date: Wed, 2 Aug 2006 22:40:29 +0100 Lines: 98 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 81.151.180.76 Message-ID: <44d11bab@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1154554795 81.151.180.76 (2 Aug 2006 14:39:55 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!newsfeed0.kamp.net!newsfeed.kamp.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail