From 7f70824e426869a1c0e9530e26bcf820e8bf9f82 Mon Sep 17 00:00:00 2001 From: mdb Date: Thu, 22 Mar 2001 03:00:25 +0000 Subject: [PATCH] Fail if we can't connect to the music daemon and get the music daemon host and port from the environment if they're in there. git-svn-id: https://samskivert.googlecode.com/svn/trunk@112 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- projects/robodj/bin/append | 17 +++++++++++++++-- projects/robodj/bin/mpcmd | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/projects/robodj/bin/append b/projects/robodj/bin/append index 17feb829..f9ec1cd7 100755 --- a/projects/robodj/bin/append +++ b/projects/robodj/bin/append @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: append,v 1.1 2001/03/22 02:41:36 mdb Exp $ +# $Id: append,v 1.2 2001/03/22 03:00:25 mdb Exp $ # # Appends the supplied song or songs to the playlist of a running MP3 # daemon. @@ -11,10 +11,23 @@ use IO::Socket; my $usage = "Usage: $0 mp3_file [mp3_file ...]\n"; my $path = shift or die $usage; +# determine our music daemon host and port +my $host = "localhost"; +if (defined $ENV{"MUSICD_HOST"}) { + $host = $ENV{"MUSICD_HOST"}; +} my $port = 2500; -my $sock = new IO::Socket::INET(PeerAddr => "localhost", +if (defined $ENV{"MUSICD_PORT"}) { + $port = $ENV{"MUSICD_PORT"}; +} + +# establish a socket connection with the server +my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => $port, Proto => "tcp"); +if (!defined $sock) { + die "Unable to connect to music server on $host:$port.\n"; +} do { # send the command diff --git a/projects/robodj/bin/mpcmd b/projects/robodj/bin/mpcmd index 35621a5d..1f7d4e73 100755 --- a/projects/robodj/bin/mpcmd +++ b/projects/robodj/bin/mpcmd @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: mpcmd,v 1.1 2001/03/22 02:41:36 mdb Exp $ +# $Id: mpcmd,v 1.2 2001/03/22 03:00:25 mdb Exp $ # # Appends the supplied song or songs to the playlist of a running MP3 # daemon. @@ -11,10 +11,23 @@ use IO::Socket; my $usage = "Usage: $0 COMMAND [ARGUMENT ...]\n"; my $command = shift or die $usage; +# determine our music daemon host and port +my $host = "localhost"; +if (defined $ENV{"MUSICD_HOST"}) { + $host = $ENV{"MUSICD_HOST"}; +} my $port = 2500; -my $sock = new IO::Socket::INET(PeerAddr => "localhost", +if (defined $ENV{"MUSICD_PORT"}) { + $port = $ENV{"MUSICD_PORT"}; +} + +# establish a socket connection with the server +my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => $port, Proto => "tcp"); +if (!defined $sock) { + die "Unable to connect to music server on $host:$port.\n"; +} # send the command print $sock "$command " . join(" ", @ARGV) . "\n";