Hi, I'm just starting to use POE. Here's a basic question I'm stuck with: I've got a simple TCP server using POE(with my own filters), which accepts some commands and responds with 1 or 0 depending on whether the commands are valid. When I test it using telnet, all is fine. What I'm trying to do is to write a simple client in POE, I'd like to make a connection, and then just send the server a sequence of commands. I'd like to be able to handle the server response for each command. But I can't seem to control how the sequence is sent: in some runs, each is sent one at a time; in some other runs, all is sent in one batch. Is there a way to make sure each command is sent individually? sort of flushing IO after each command?
#!/usr/bin/perl -w
#
# simple client
#
use warnings;
use strict;
use POE;
use POE::Component::Client::TCP;
use POE::Filter::Stream;
my $host = "localhost";
my $port = 38888;
POE::Component::Client::TCP->new(
RemoteAddress => $host,
RemotePort => $port,
Filter => "POE::Filter::Stream",
Connected => sub {
print "connected to $host:$port ...\n";
#now send 10 commands in a row.
# is this the right way to send a sequence?
foreach my $i(1..10){
$_[HEAP]->{server}->put("command-$i");
}
},
ConnectError => sub {
print "could not connect to $host:$port ...\n";
},
ServerInput => sub {
my ( $kernel, $heap, $input ) = @_[ KERNEL,HEAP, ARG0 ];
print "$input\n";
},
);
POE::Kernel->run();
exit 0;
UPdated: it still doesn't seem to work if I add "\n" to the end of commands, and use the Line filter.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.