in reply to nonblocking UDP, "Hello World" level

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

Replies are listed 'Best First'.
Re^2: nonblocking UDP, "Hello World" level
by Bruce32903 (Scribe) on Dec 06, 2006 at 11:58 UTC
    Thanks for the info. I won't get to try working with it until tonight. I did find various pages while Googling that used POE. What stopped me were the references to "kernel" and "heap" and the larger size of "simple example" programs. I got the feeling that POE might be an area for Monks and with only a few hours a week to work on this I might not be able to snatch the pebble from his hand.

    Thanks
    Bruce