On Mon, Apr 11, 2011 at 08:50:59AM +0300, Shlomi Fish wrote: > Hi Siegfried, > > On Sunday 10 Apr 2011 21:55:30 siegfr...@heintze.com wrote: > > I want to implement a implement a poor man's ftp server that has minimal > > dependencies (like none!). I'll write a simple custom poor man's ftp > > client on the other side. Since I'm writing both the client and the > > server, I don't need to worry about adherence to the ftp standard -- > > only the concept. > > > > So how can I write a simple perl program that waits on a TCP socket for > > a file name followed by the file contents (I don't need to worry the > > path names -- everything goes in the same directory). > > > > Can I assume that an entire perl source code file will fit in a single > > socket packet? I've only used print statements before. I could write a > > single record per the call to the socket send function. Is there a > > better way? (I hope so!) > > > > Recommendations are welcome! > > Please look at http://cpan.uwinnipeg.ca/dist/POE-Component-Server-FTP or a > similar module for one of newer event-based systems, such as IO::Async, > AnyEvent, IO::Lambda or Reflex . These allow you to easily code a custom FTP > server or client.
I'm not sure any of these really meet the requirement in the first sentence above (minimal dependencies). If you take a look at the perlipc document (perldoc perlipc) then the second half, starting with the section "Sockets: Client/Server Communication", provides some explanations and source code you can copy and expand upon. I'm not really sure what you mean in your third paragraph. Using print is fine to send data to a socket, but you'll obviously need to be careful based on whatever protocol you use and the data you need to send. If you are worried about efficiency then I suspect the IO costs will outweigh cpu costs but, as always, get the code working before worrying about whether it is fast enough. -- Paul Johnson - p...@pjcj.net http://www.pjcj.net -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/