Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://919142]
jkva dusts the floor
[karlgoethebier]: Totally OT but my pleasure: Next week i'll have my first archery lesson.
[Corion]: Hi jkva!
[Corion]: karlgoethevier: Oooh, that sounds interesting! ;)
[karlgoethebier]: btw, good morning

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-10-20 09:53 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (260 votes). Check out past polls.