Seeing the expression 'non-blocking' immediately makes me think POE.

This is a simple Echo server using POE::Kernel and POE::Wheel::SocketFactory :

use strict; use warnings; use POE; use POE::Wheel::SocketFactory; use Socket; POE::Session->create( package_states => [ 'main' => [ qw(_start _sock_up _sock_err _sock_read) ], ], ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_[KERNEL,HEAP]; $heap->{factory} = POE::Wheel::SocketFactory->new( SocketProtocol => 'udp', BindPort => 9090, SuccessEvent => '_sock_up', FailureEvent => '_sock_err', ); return; } sub _sock_up { my ($kernel,$heap,$socket) = @_[KERNEL,HEAP,ARG0]; delete $heap->{factory}; $kernel->select_read( $socket, '_sock_read' ); return; } sub _sock_err { my ($heap,$op,$errno,$errstr) = @_[HEAP,ARG0..ARG2]; delete $heap->{factory}; warn "$op $errno $errstr\n"; return; } sub _sock_read { my ($kernel,$socket) = @_[KERNEL,ARG0]; my $remote_address = recv( $socket, my $message = "", 1024, 0 ); return unless defined $remote_address; send( $socket, $message, 0, $remote_address ) == length($message) or warn "Trouble sending response: $!"; return; }

There are many examples in the POE Cookbook


In reply to Re: nonblocking UDP, "Hello World" level by bingos
in thread nonblocking UDP, "Hello World" level by Bruce32903

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.