It seems there is a handy "Started" argument to PoCo::Client::TCP::new.
You can also do effectively the same thing by establishing a closure
around $site below in one or more of your PoCo::Client::TCP event
handlers.
The following is untested:
use POE qw(Component::Client::TCP);
foreach my $site ( qw/ site1 site2 site3 / ) {
POE::Component::Client::TCP->new
( RemoteAddress => $site,
RemotePort => 6789,
#Started => sub { $_[HEAP]->{sitename} = $site; }, #
could do it with a closure
Started => sub { $_[HEAP]->{sitename} = $_[ARG0]; }, #
not a closure
Args => [ $site ],
ServerInput => sub {
my ( $kernel, $heap, $input ) = @_[ KERNEL, HEAP,
ARG0 ];
my $sitename = $heap->{sitename};
# print "got input from $site: $input\n"; # a
closure gets you the same thing
print "got input from $sitename: $input\n";
},
);
}
-
Lance Braswell - + 1 469 357 6112
Jeff Konz <[EMAIL PROTECTED]>
09/09/2004 09:17 PM
Please respond to
Jeff Konz <[EMAIL PROTECTED]>
To
[EMAIL PROTECTED]
cc
Subject
Setting a variable in the heap
Hello,
I am a new user of POE and I have a script that creates a connection
to a tcp server and am processing the data coming from that server. I
have 7 different servers that I run the script against.
I would like to create a single POE script that does what I need. I
know that I can set up individual sessions within the script to handle
this. In order to process the data, my state needs to know what
system the data comes from.
The easiest way I see to do this is to have a variable in the sessions
heap that is something like:
heap->{sitename} = site1
So my question is two fold, first is this the proper syntax to do this
and second if it is, where do I put this statment within the POE
script( I.E. Within the new() construct of the
POE::Component::Client::TCP or somewhere else)?
I have read the docs that are available, but I can not find a
reference to setting vars within the heap.
Thanks for any help you can provide,
Jeff