Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Answer: How do I send a file through a Socket Connection ?

( #6010=categorized answer: print w/ replies, xml ) Need Help??

Q&A > network programming > How do I send a file through a Socket Connection ? contributed by chromatic

The IO::Socket package inherits from IO::Handle, so you can treat your socket (after it's all set up) like a filehandle. You can print to it or read from it! Just do something like:
open(INPUT, $my_file) || die "Can't open: $!"; print $connection while (<INPUT); close(INPUT) || die "Can't close: $!";
Disabling buffering ($| = 1) might be a good idea. You can also call select on the $connection object.

On the server side, you can just read from the socket (once it is set up) with the normal angle operators. Using the accept() method will cause the server to listen to the socket until it gets a response, and it will return an object with filehandle properties. Whatever you want to do with it from there is up to you, once it's in a scalar or an array.

Comment on Answer: How do I send a file through a Socket Connection ?
Download Code
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-04-19 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls