Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Socket programming

by thenaz (Beadle)
on Aug 08, 2011 at 03:01 UTC ( #919138=note: print w/ replies, xml ) Need Help??


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?


Comment on Re: Socket programming
Re^2: Socket programming
by Anonymous Monk on Aug 08, 2011 at 06:00 UTC

    I think you're correct. I can handle the incoming packets on the same thread. This was actually very helpful because I forget that UDP is stateless - hopefully my bone-headed question helps someone out in the future.

    My goal is to create a simple SIP proxy in our very non-standard environment. So, what I should do is create a fork (or what-have-you) for each new unique conversation identifier (as required in SIP) and do exactly what you said in your third paragraph.

      Also see Net::SIP, which should have large parts of a SIP client and server.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://919138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-09-21 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls