Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi
I have 2 simple scripts to send short files from a win2k box to HP unix box ( for learning purposes only). They work fine, but I am looking for ideas on why the client (win2k) needs a sleep statement after each line write. If I leave it out, I get a "Connection reset by peer" on the receiving end(unix) Thanks and the relative code is below:
# Server (Receiver on Unix end) if ($pid = fork) { # parent close(C); waitpid( -1, &WNOHANG ); next; # ready for another client } else { # child die "can't fork: $!" unless defined $pid; close(S); print C "Connected to $ip:$port "; # get file name sysread(C, $fname, 128) or die "couldn't read: $!\n& +quot;; $fname =~ s/\n//; print "recieving file: $fname\n"; while ( sysread(C, $buf, 128) ) { $msg .= $buf; } open (F, ">$fname") or die "couldn't ope +n it: $!"; # open a new file with the file name and write to it print F $msg; close F; print "Recieved file\n"; exit; } ------ # client (win2k sender) socket(SOCK,AF_INET,SOCK_STREAM,$proto) || die "$0:Cannot open so +cket\n"; connect(SOCK, $remote) or die "can't connect: $!\n"; # send filename to server print "sending file $fname\n"; $bytes = syswrite(SOCK, $fname, length($fname)); sleep 1; open(F, "<$fname") or die "coundn't open: $!"; @buf = <F>; foreach $line (@buf) { # why do we need to sleep ? syswrite(SOCK, $line, length($line)) or die "can't write: $ +!"; sleep 1; } close F;
 editted by jeffa - s/pre/code/g 

In reply to IO over socket by neptuna

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2021-10-27 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (91 votes). Check out past polls.

    Notices?