Your problem is that you send the filename and the content of the file without any marker in between. Without the sleep both the name and the content might be send in a single packet, especially if the file is small. Assume for instance you have a 50 byte file, and a 20 byte filename. You send 70 bytes, and those 70 bytes will be read at the receiving end at your first sysread. By the time you get to the second sysread, in the loop, the sending end has already finished sending the data and closed the socket.
Your problem is that you are mixing protocols. It seems you like to do a line based protocol, first sending the filename, then the content, line-by-line, but you are using
a bytestream mechanism for it. If you want to do it line-by-line, just use print (on the sending end) and <$socket> (on the receiving end).
Abigail
-
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 How to display code and escape characters
are good places to start.
|