Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

After looking into POE (which is lovely and clever), I've decided to use SocketFactory for my tcp server needs. This is great until I get into some error handling. I usually set alarms, which do some clean up, and then close the socket. I close the socket to get the connection to drop, thus allowing the client to drop off.

Normally, I just use close(). But I need the socket name for that, and I have no idea how to find the socket that I'm using inside a session.

I tried using getsockname with no success. Any monks out there know either how to close a particular socket, or where the HEAP keys are documented?

Here's a sample of what I'm trying to do. Also, my clients don't have access to ALARM (Winders), so the drop has to happen on my end.

#!/usr/bin/perl use POE qw( Wheel::SocketFactory Wheel::ReadWrite Filter::Line Driver::SysRW ); new POE::Session ( _start => \&collector, agent_handler=>\&agent_handler, accept_failed=>\&accept_failed, agent_input=>\&agent_input, agent_error=>\&agent_error ); $poe_kernel->run(); exit; # Session Sub Defs sub collector { $_[HEAP]->{listener} = new POE::Wheel::SocketFactory ( BindPort => PORT, Reuse => 'yes', SuccessEvent => 'agent_handler', FailureEvent => 'accept_failed' ); print "SERVER: Started Collector on port ",PORT,"\n"; } # Non-Session Sub Defs sub accept_failed { my ($function, $error) = @_[ARG0, ARG2]; delete $_[HEAP]->{listener}; print "SERVER: call to $function() failed: $error.\n"; } sub agent_handler { print "Agent handler called\n"; my ($heap, $socket) = @_[HEAP, ARG0]; $heap->{readwrite} = new POE::Wheel::ReadWrite ( Handle => $socket, Driver => new POE::Driver::SysRW (), Filter => new POE::Filter::Line (), InputEvent => agent_input, ErrorEvent => agent_error, ); $heap->{peerhost} = inet_ntoa($_[ARG1]); print "CHILD: Connected to $heap->{peerhost}.\n"; } sub agent_input { $heap=$_[HEAP]; print "agent_input called\n"; $input_sysid=$_[ARG0]; print "input system id is $input_sysid from $heap->{peerhost}\n"; print "Sending ack back\n"; $heap->{readwrite}->put( "Hello, client!" ); $agent_alarm = $poe_kernel->delay_set( agent_error, 5 ); } sub agent_error { print "Got an agent error, exiting agent session!\n"; my ($function, $error) = @_[ARG0, ARG2]; print "SERVER: call to $function() failed: $error.\n"; # I sure would like to close the socket here... }


In reply to How do I close a POE SocketFactory Socket? by Declarent

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (9)
    As of 2018-03-17 10:51 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (223 votes). Check out past polls.