If I understand correctly, you want the server to start talking first. That's easy, really. POE::Wheel::ReadWrite instances are ready to be used immediately.

sub agent_handler { # ... my $wheel = new POE::Wheel::ReadWrite(...); $heap->{wheel}->{$wheel->ID} = $wheel; $wheel->put("Greetings from MyServer version 1.0"); # ... }

POE can be used to write single-tasking programs that block, but network servers don't usually don't fall into this category. It's possible to block temporarily, though, and short blockages might go unnoticed. (Actually, a POE program is just a series of very short blocking operations. They usually occur quickly enough that people don't notice.)

The heap is reserved almost entirely for your storage. Its main purpose is to store persistent information between events. If I understand your question, this is exactly what you want to do.

If you decide to keep copies of socket handles in the heap, be sure to delete them when you're done with them. Otherwise your server will leak memory and file handles, and it will crash in short order.

sub agent_handler { # ... $heap->{wheel}->{$wheel->ID} = $wheel; $heap->{socket}->{$wheel->ID} = $socket; # ... } sub agent_error { # ... delete $heap->{wheel}->{$wheel_id}; delete $heap->{socket}->{$wheel_id}; }

If at all possible, however, you should use $wheel->put() to send data. Your $socket is in non-blocking mode, and all the standard caveats about print() and <> apply.

More notes.

If you're going to store a lot of things in the heap for each wheel, consider turning things inside out.

$heap->{$wheel->ID} = { wheel => $wheel, socket => $socket, foo => $foo, };

Then you can delete it all at once.

delete $heap->{$wheel_id};

Interview? I get this sort of Q&A all the time. :)

-- Rocco Caputo / poe.perl.org / poe.sf.net


In reply to Re: Re: Re: Re: Re: How do I close a POE SocketFactory Socket? by rcaputo
in thread How do I close a POE SocketFactory Socket? by Declarent

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.