Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by ljamison (Sexton)
on Mar 02, 2017 at 21:18 UTC ( [id://1183470]=note: print w/replies, xml ) Need Help??


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

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.

  • Comment on Re^4: How to share a non-blocking IO::Socket::INET server/pass "listening" control?
  • Download Code

Replies are listed 'Best First'.
Re^5: How to share a non-blocking IO::Socket::INET server/pass "listening" control?
by haukex (Archbishop) on Mar 04, 2017 at 08:45 UTC

    Since you're already working with POE, it makes sense to me to do everything with it. See the POE Cookbook, e.g. "TCP Clients" for how to establish a client connection, and the example "TCP Port Redirection", while a bit complex, shows how to have one program be both server and client.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-20 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found