Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2016-05-01 06:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found