Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: IO over socket

by Abigail-II (Bishop)
on Jun 22, 2004 at 13:02 UTC ( #368698=note: print w/ replies, xml ) Need Help??


in reply to IO over socket

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


Comment on Re: IO over socket
Download Code
Re^2: IO over socket
by neptuna (Novice) on Jun 22, 2004 at 19:52 UTC
    Thanks. Funny that you mentioned the "Marker" in between the file name and the data. 

    I was also looking for the best way to do that. I prefer using a byte stream

    for the actual transfer but again not sure how to separate the file name from the file data. Thanjs again for your help

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://368698]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (17)
As of 2014-09-22 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (195 votes), past polls