Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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?

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://919138]
[Eily]: sorry, got interrupted
[Eily]: so he left from Nancy
[Eily]: and my point was, he met some monks yesterday in Italy who offered him a place for the night
[Eily]: and since he was meating eatalian monks I wondered if I should tell him to say hi to Discipulus for me :D
[erix]: Nancy-Bari: 1320 km ... He'll need some time :)
[LanX]: he was "meating" Italian monks oO?
[erix]: then again, there are people who do 10 full triathlons on 10 consecutive days, so it must be doable
choroba's friend has done the Pacific Crest Trail, it's 4200 km

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-12-13 15:08 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (369 votes). Check out past polls.