Greetings oh wise ones. I'm working on a simple client/server script that just talks back and forth, but I'm having trouble with the script not processing my if statements after data is sent to it. I will then however continue on after more data is sent and stop again at the same place. The ####Problem here.#### is where the server stops after I send it the first bit of information. Here is the code minus some of the basic socket stuff which I omitted.

Server
while(1){ $MySocket->recv($text,2); if($text ne '') { print "\n Number'", $text,"'\n","\n"; ####Problem here.#### if($text=~m/\d.*/){ print "\nThat's a number"; }else{ print "\nNot a number"; } }else{ print "Cilent has exited!"; exit 1; } }
Client
print "\n",$def_msg; while($msg=<STDIN>) { chomp $msg; if($msg ne '') { #print "\nSending message '",$msg,"'"; if($MySocket->send($msg)){ print ".....<done>","\n"; print $def_msg; } } else { # Send an empty message to server and exit $MySocket->send(''); exit 1; } }

After the server reads in the input it runs the print statement with the:

print "\n Number'", $text,"'\n","\n";

But it won't run the if statement after it until I sent another piece of data from the client E.G. I fire open the client and type in the number 1 then hit enter. My server prints this output:

>> Server Program << Number'1'

And stops there until I enter something else on my client; say I enter the number 2. My server now looks like this:

>> Server Program << Number'1' That's a number Number'2'
So it moved on to the if statement only after seeing more input from the client. Any ideas?

In reply to IO Socket INET stopping in middle of script by oosnoopy

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.