http://www.perlmonks.org?node_id=1008923
PM_Visitor has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perl Monks:
I am trying to write a GUI tool in Perl/Tk. It's purpose is to drive equipment at work, which is a
digital cross connect system. I have have almost everything debugged and working in a simulation mode.
What I haven't yet figured out is the network communication part.

When I use the stock Microsoft Telnet program, the server responds properly, the response is immediate.
For both a "!" response to a CR, and for a command sent. Works properly.

When I use Perl's socket functions in my Client (use Net::Telnet on the Client) and (use Socket) on the server,
I have to send another "!" for the Client to show the data on the screen.

I figure that since the stock Telnet program works properly, it's not the server (use Socket).

My Client's local console gets updated the same time as the Tk text window.
(after ! is sent after a command is sent to the server).

In my program the Perk/Tk GUI... the link partially works. (1 for 1 with a ! sent),
but when I send a command an extra CR/! is needed for data to appear on the client side
(on both console and Tk windows). (Yes, I repeated myself, sorry... and I think I repeat below as well).
-------------------------------------------------------------------------------
Here are code samples. Client side, and this works... gets an immediate response. (which is a "!")

$t->print("!"); my $data = $t->get(); print STDOUT "$data\n"; WriteToScreen($data); return;

-------------------------------------------------------------------------------
Client Side, and this does not work... I have to enter another ! (the above) to get a response.

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);
-------------------------------------------------------------------------------
My program's write sub: (the scroll bar works ok, everything else works ok).
sub WriteToScreen { my ($msg) = @_; $screen->insert("1.0", $msg); $numlines = ($screen->index("end")-1); $screen->configure(-state => "normal"); if ($screen->index("end-1c") != "1.0") { $screen->insert_end("\n"); } $screen->insert_end($msg); $screen->see("1.0"); $screen->configure(-state => "disabled"); $screen->yview("end"); }
-------------------------------------------------------------------------------
Data being sent by the server: (works with stock telnet, does not work with my program (as above):

$cm1 = "M 11:24:49 25,00 7 UTL QRY CMAP 064 TODC---- TYPE DC102 4 LN M +SG:\r\n 04124 20003 19317 19318 00000 19320 19324 19315\r\n 19323 19314 19316 19319 00000 19601 00000 20103\r\n 19604 07301 07302 07303 00403 07304 19407 19410 COMPL\r\n";

-------------------------------------------------------------------------------
This is the key routine in the server... sends the above data.

if ($cmd =~ m/cmap 111/ig) { select (NS); $|= 1; select (NS); print NS "$cm1"; print NS "\n"; print STDOUT "$cm1"; }

This is the portion of the server that sends the ! in response to a !:

if ((length($ll) < 3) && ($ll !~ /!/g)) { print NS "!"; print STDOUT "3!\r\n"; next; }
This is my first post here. Sorry if it is not what is wanted. I don't get what I'm doing wrong. At the risk of repeating myself... When I send a ! I get a ! right back (my choice of a communication indicator). No delay, nothing further needed. When I send a command (in this case cmap 111), the data does not come back to the client until another ! is sent.

Any ideas on what might be causing this? I've got the buffers set hot ($|=1;) and I have a good pipe between the two endpoints (at this time it is just thru my local computer's stack... two different ports). The server script uses the Socket code. The Client uses Telnet code. Should I go to Socket code on the Client...? Are there incompatibilities between the two systems? I assume since Telnet works ok, the server code is ok. I realize that programming is not a spectator sport, and that I'm not really a programmer. But I'm trying. Have tried, and have worked this one over a lot before posting here. Thanks in advance for your help.