Hi monks,

I am trying to learn how to write perl modules (this is my first one) and have run into a bit of a problem. Below is the module I am writing (it's spose'd to interface with a Festival server). It's all working execpt for the speak sub, specifically the syswrite command. I keep getting an error "broken pipe" but dont know how to resolve this.
Can anyone give me any hints?
Cheers,
Reagen

package Voice; # ::: External modules used by this module ::: # use IO::Socket; ################################################# # Method: Voice->new # Description: Object Constructor method ################################################# sub new { # bless a new object shift; my $self = {}; bless($self); # Set params passed for the object my ($server, $port) = ('localhost', 1314); # ::: Set Object Parameters ::: # $self->{ERROR} = undef; # error (duh!) $self->{SERVER} = $server; # festival server $self->{PORT} = $port; # festival port $self->{PRO} = 'tcp'; # connection protocol $self->{CONN} = undef; # connection object # return the object return $self; } # end-new # ----------------------------------------------- ################################################# # Method: Voice->open # Description: open the festival connection ################################################# sub open { # set as method my $self = shift; # create a connection to the festival server using IO::Socket::INET if ($self->{CONN} = IO::Socket::INET->new( Proto => $self->{PRO}, Pe +erAdr => $self->{SERVER}, PeerPort => $self->{PORT} )) { } # end-if else { # set the error string $self->{ERROR} = "Could not open connection to the festival server +!"; } # end-else } # end-open # ----------------------------------------------- ################################################# # Method: Voice->speak # Description: say the sentence ################################################# sub speak { # set as method my $self = shift; # read in the sentence my ($sentence) = @_; my $buffer = "(SayText \"" . $sentence . "\")\n"; # say the sentence if ( syswrite($self->{CONN}, $buffer, length($buffer) ) ) { } # end-if else { # set the error string $self->{ERROR} = "Could not say sentence!"; } # end-else } # end-prepare # ----------------------------------------------- ################################################# # Method: Voice->close # Description: close the festival connection ################################################# sub close { # set as method my $self = shift; # close the IO::Socket::INET connection shutdown($self->{CONN}, 2); close($self->{CONN}); } # end-close # ----------------------------------------------- 1;

In reply to Broken Pipe error when talking to Festival server by rsiedl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.