Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Socket programming

by chubako (Acolyte)
on Aug 08, 2011 at 05:10 UTC ( #919142=note: print w/ replies, xml ) Need Help??


in reply to Socket programming

Not sure that it works right, but it works. :)

use strict; use warnings; use Socket; use AnyEvent; my $udp_server my $udp_socket; sub start_udp_server { my $port = shift || 9000; my $proto = getprotobyname('udp'); my $paddr = Socket::sockaddr_in($port, Socket::INADDR_ANY); socket($udp_socket, Socket::PF_INET, Socket::SOCK_DGRAM, $proto); bind($udp_socket, $paddr); $udp_server = AE::io $udp_socket, 0, sub { my $buff; my $addr = recv($udp_socket, $buff, 256, 0); print $buff; } } start_udp_server(); my $ae_timer = AE::timer 10, 10, sub { print "timer tick\n"; } AE::cv->recv;
You can check it with nc/netcat/ncat:
ncat -u localhost 9000


Comment on Re: Socket programming
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2015-07-04 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls