Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Nonblocking read server

by Carbonblack (Novice)
on Aug 30, 2019 at 06:55 UTC ( [id://11105290]=note: print w/replies, xml ) Need Help??


in reply to Re: Nonblocking read server
in thread Nonblocking read server

Thank You very much for your advice!

That was the answer i feared ;-) But it makes it a lot easier.

I think, I'll avoid fork or Async etc. this time since i expect only a one way communication and i want to use as less resources as possible.

Replies are listed 'Best First'.
Re^3: Nonblocking read server
by tybalt89 (Monsignor) on Aug 30, 2019 at 14:41 UTC

    Just to show you why I recommended an Async package, here's your problem done using my own Async::Tiny. It should be similarly short in any of the other Async packages.

    #!/usr/bin/perl use strict; use warnings; use Async::Tiny; use Path::Tiny; use constant PORT1 => 5000; my $connID; my $t = Async::Tiny->new; $t->addListenCallback( PORT1, sub { my $sock = shift; $t->addReadCallback($sock, \&process_message, $sock->peerhost, ++$co +nnID); $t->changeReadMode($sock, 'full'); }); $t->eventloop; sub process_message { my ($data, $peerhost, $id) = @_; my $filename = "rcv_${id}_$peerhost.txt"; path($filename)->spew_raw($data); print "[save process_message] wrote $filename\n"; }

    See - nice, simple, clean, short :)

    Where Async::Tiny is

      > my own Async::Tiny

      Any plans to CPANify it?

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        I've been thinking about it, but it really needs a humongous test suite ( much more than the 50 or so test programs I have now ) and it needs automation of client/server test cases which now require visual validation, and "more silly excuses"x100 .

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found