in reply to Socket programming
I agree with zwon that forking or spawning a thread each time a UDP datagram shows up is probably not the way to go (especially since Perl ithreads are somewhat resource intensive).
You may choose to use an event loop, which is much lighter-weight, and offers the ability to process things asynchronously. Check out IO::Poll. But reading your last paragraph/question, I'm not sure that's really what you want.
In UDP, every packet is independent (i.e. UDP is connectionless), so you don't end up with a client socket object that you can dispatch to a thread (like you would in TCP). What you might want to do, is to pre-fork, or pre-spawn some threads, and then as you read packets off the socket in the main thread, examine them as needed and route to the appropriate child thread/process.
Of course, depending on what you are doing, I can't shake the feeling that you may not actually need threads at all. Why can't you just receive a packet, process it, then receive another, etc--all on the same thread?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Socket programming
by Anonymous Monk on Aug 08, 2011 at 06:00 UTC | |
by Corion (Patriarch) on Aug 08, 2011 at 06:59 UTC |