Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jun : Re: TidUDPServer question
| Subject: | Re: TidUDPServer question |
| Posted by: | "Richard Bibby" (richard.bib..@profdoc.se) |
| Date: | Fri, 2 Jun 2006 21:40:34 |
Hej,
Thanks for you long reply. It has certainly given me something to think
about.
I didn't know about the threading of the TCPServer so i'll have a look...
/Richard
"Jamie Dale" <j.dale@turboz.net> skrev i meddelandet
news:44802576@newsgroups.borland.com...
>
> Ok, I'm no expert here but I've been experimenting with Indy for a few
> years so here's my shot:
>
>> I am writting a service application that recieves messages, processes
>> them, and sends a response.
>
> Cool, sounds similar to something I've been working on.. (Instant
> messenger though I use TCPserver/Client..)
>
>> I am using a TidUDPServer to handle the incoming messages. Then I start
>> a thread to actually process the message. Each thread will then send a
>> response back to the originator of the message.
>
> I never did that. I'm not sure but I thought ALL indy servers were
> multithreaded anyway?
> Not sure but if your UDPserver is multithreaded like the TCPserver, then
> you don't need to fire a seperate thread as it will automatically create a
> new thread instance and execute the code you've written in the unit.
> Though beware, this has been my achilles heel in the past: My tcp thread
> could not send commands to a component on the form - I had to put the text
> into a public string and set a timer to read it..
>
> Now I ain't sure about UDPserver but assuming its the same as the TCP you
> just need to write your handling code (IE, process the message, do
> database lookup [ini files are surprisingly good too] etc and send
> response) and the UDPserver will automatically thread it with a new
> instance based on your unit at runtime.
>
>> My question is will I have a problem when trying to send messages in my
>> threads? I can end up in the situtuation that more than one will try to
>> respond at the same time. I was thinking that each thread would create
>> an instance of TidUDPServer to Send the data. Am I going to run into
>> trouble because sooner or later two or more TidUDPServer components will
>> be reading/writing to the same port? Should I route all my transmissions
>> through a since thread so as to avoid any concurrency problems?
>
> If Indys UDP server is the same as TCP - Multithreaded you can simply
> write your code in the same unit as the UDP event handlers and then
> compile and run. The UDPServer will keep track of all the threads etc
> automatically (Though you might need a threadpool component - in the Indy
> [servers I think] tab on the pallette) and handle them automatically. Indy
> really is the way to go in that respect as it makes threaded servers so
> much easier to handle.
>
> Hope this helps