Hello and thanks for your reply! Unfortunately, the peer I'm connecting to is proprietary software and it can't be changed, unfortunately. The way I described it is the way in which the peer expects to communicate.
When I connect to the peer on port 8001, I send a message (MESG) and get an ACK reply (with code RESP). After the MESG and RESP are sent/received, respectively, the peer is designed to initiate a connection to port 8000 and send a STAT notifying of the status of the entry in the database (i.e. for addSomething - if it already existed in the database the STAT would provide the code indicating so).
| [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] |
Unfortunately, it appeared that IO::Select mechanics don't play well with this remote system. The most success I've had so far was with POE::Component::Server::TCP. After some discussion with Rocco, the author of POE, I now have a functional setup for the most part. I asked a new question and didn't continue on one of the other questions I had asked because it's not something I was able to find an answer on anywhere else and I didn't want it buried in comments. Because the majority of the script logic is proprietary, I had to redact a lot of it but the basic idea of what I have working now using POE is:
#!/usr/bin/perl
#
## *NOTE* this script is ran via terminal
#
#
use strict;
use warnings;
use POE qw(Component::Server::TCP);
# brian d foy's Modulino design pattern
__PACKAGE__->poeServer(@ARGV) unless caller
sub poeServer {
POE::Component::Server::TCP->new(
Started => sub {
warn "Server started!\n";
},
Port => 8000,
ClientConnected => sub {
warn "Client connected!\n";
},
ClientDisconnected => sub {
warn "Client disconnected!\n";
},
ClientInput => \&client_input,
# because peer is SOCK_STREAM
ClientFilter => "POE::Filter::Stream",
Stopped => sub {
warn "Server stopped!\n";
},
);
POE::Kernel->run();
exit;
}
sub client_input {
my ($input) = $[ARG0];
warn "Client sent: $input\n";
my $reply = "00000";
# Acts as ACK to peer confirming data persisted
$_[HEAP]{client}->put($reply);
}
sub ADD {
my $handle = IO::Socket::INET->new(
PeerHost => "XX.XX.XX.XX", # redacted
PeerPort => 8001,
Proto => "tcp",
Type => SOCK_STREAM,
);
my $message = "12345ABCD";
$handle->send($message);
my $data;
$handle->recv($data, 10);
warn "Peer server responded with: $data\n";
$handle->close();
#### Need some way of being notified!
}
This code works very well for accepting the messages initiated by the peer without getting hungup waiting on data..just what I wanted on that end!
Also, I am able to initiate a client-side connection to the server on port 8001 (in the example code above, the ADD subroutine). However, once the client-side connection has sent its data and disconnected, what I need is it to somehow notify ADD with the status as it arrives. I'm certainly open to suggestions because at the moment I'm at my wit's end trying to figure out how to notify ADD when the status is sent. | [reply] [Watch: Dir/Any] [d/l] |