Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Telnet Client/Server: What am I doing wrong?

by RichardK (Parson)
on Dec 15, 2012 at 17:45 UTC ( #1008999=note: print w/replies, xml ) Need Help??

in reply to Telnet Client/Server: What am I doing wrong?

print STDOUT "Get_CMap() Live Mode\n"; select($t); $t->print($CMap_cmd); $t->flush(); # this flushes the ouput buffer, but it is $|=1 anyway. $newCMapData = $t->get(); print STDOUT "$newCMapData\n"; WriteToScreen($newCMapData);

What is the select in this code for? i.e. what do you think it's doing ?

and why do you need the flush?

Replies are listed 'Best First'.
Re^2: Telnet Client/Server: What am I doing wrong?
by PM_Visitor (Initiate) on Dec 16, 2012 at 01:19 UTC

    Hi RichardK....
    To answer as best I can... The selection of the output file handle 'select($t)' is not needed---now I realize that it is not necessary since '$t->print()' directs output to the file handle (which is the socket). The $t->flush() is an attempt to ensure that the command is sent--I learned this also is not necessary.

    Then I get the response (which is buffered and not displayed until another carriage return is sent. Which is the key problem that I'm stuck on).

    I can get the link to work by calling my 'SendCR()' Client sub (which merely sends a a "!\n"). So that's my work around, until I can fathom the process. I've been reading and working examples. The work around will do for the rest of the program development...but it's not technically the right answer. (sigh). Thanks for your response.

    I don't want anyone to debug my program for me... the previous post asked for working examples... it's difficult to cut out brief parts... sorry that was not enough to relay the problem. It will shine when it shines. The learning curve is the difficult to cross at times. Thanks again, take care.

      the previous post asked for working examples... it's difficult to cut out brief parts

      Though it may be difficult, it's a good training exercise for you in learning Perl. The act of creating a small cut-down program should help you focus on and better understand the problem; you may even find you're able to identify the problem and fix it yourself.

      BTW, instead of your global NS file handle and the:

      select (NS); $|= 1; select (NS);
      claptrap, you should use a lexical file handle ($ns say) and then simply:
      use IO::Handle; # ... $ns->autoflush();
      With recent Perls (5.8+), there's no need anymore to confusingly change the (global) default destination for print statements via the old evil one-argument form of select -- for more details, see Perl Best Practices, chapter 10 and Perl tip: Buffering and IO::Handle (for Perl 5.14+ you don't need use IO::Handle).

      Suggest you further read Suffering from Buffering.

        Thank you for the feedback and document references!
        I'm going to continue to read the Lincoln Stein Book, will check out the Best Practices book as well.
        I have read the Suffering from Buffering! A good read, indeed :).

      You said you were using Net::Telnet for the client, but I can't see a method called SendCR in the pod Net::Telnet. So what are you using, and have you read the docs? :)

        Richard: The action of the SendCR is stated above. Sure, I've read *many* documents, and will continue to.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008999]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-06-23 20:50 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.