Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to read from a socket file created by vlc's rc interface here. As I am doing it via cgi, I need to chop the otherwise interactive stream of comand-response-command-etc. into consumable chunks.
Some of my code:
Some of my code:
Is there a more elegant way to detect when the socket stops to spit out data? (As some outputs tend to lack my "stop words")# establish connection my $socket = IO::Socket::UNIX->new( Peer => '/path/to/socket.file.sock', ) # issue command and read answer print $socket "$some_command\n"; $html = "<html>". sockread($socket) "</html>"; sub sockread { my $socket = shift; my $content; while (my $line=<$socket>){ $content .= $line; last if $line =~ /\[ End of /i; # vlc's rc is +a bit inconsistent, some end like this last if $line =~ / returned 0 /i; # others like +this } return $content; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Chunked unix socket file reading - how?
by snoopy (Curate) on Nov 18, 2009 at 19:53 UTC | |
by Anonymous Monk on Nov 18, 2009 at 21:01 UTC | |
by snoopy (Curate) on Nov 18, 2009 at 21:59 UTC | |
by Anonymous Monk on Nov 18, 2009 at 20:45 UTC | |
by Anonymous Monk on Nov 18, 2009 at 19:56 UTC | |
by Anonymous Monk on Nov 18, 2009 at 20:26 UTC | |
Re: Chunked unix socket file reading - how?
by almut (Canon) on Nov 18, 2009 at 19:44 UTC | |
by Anonymous Monk on Nov 18, 2009 at 19:54 UTC |
Back to
Seekers of Perl Wisdom