Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: How to make EOF?by samtregar (Abbot) |
on Mar 04, 2009 at 06:35 UTC ( [id://748009]=note: print w/replies, xml ) | Need Help?? |
There isn't an end-of-file character, per-se. You can cause the other end of a socket to detect an EOF by closing the socket. When the other end finishes reading what you wrote eof(SOCKET) will return true.
If you need the other end to read multiple files then you'll need to rely on some convention. Personally I prefer to prefix potentially long transmissions with the size of the transmission rather than relying a special character which could someday appear by accident in the data stream. For example on the sending side: print WRITER length($yaml), "\n", $yaml; Then the reader can do:
Possibly interesting side-note - I was just reading the memcached protocol spec and this is exactly how it works too. -sam
In Section
Seekers of Perl Wisdom
|
|