Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to share a non-blocking IO::Socket::INET server/pass "listening" control?

by VinsWorldcom (Prior)
on Mar 02, 2017 at 19:08 UTC ( [id://1183458]=note: print w/replies, xml ) Need Help??


in reply to How to share a non-blocking IO::Socket::INET server/pass "listening" control?

You could just open another server on port 8001 and use select to listen for connections on either one. Why can't you just send your request and status on the $server port 8000?

Replies are listed 'Best First'.
Re^2: How to share a non-blocking IO::Socket::INET server/pass "listening" control?
by ljamison (Sexton) on Mar 02, 2017 at 20:02 UTC

    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).

      Wasn't this answered in Async socket connection? What about those answers didn't work and what code from that did you try?

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1183458]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-03-28 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found