Here's a really simplistic example of sending a file across a socket. Here's the server:
And here's the client:use IO::Socket; my $server = IO::Socket::INET->new( Listen => 5, LocalAddr => 'localhost', LocalPort => 5050, Proto => 'tcp' ) or die "Can't create server socket: $!"; my $client = $server->accept; open FILE, ">out" or die "Can't open: $!"; while (<$client>) { print FILE $_; } close FILE;
This should get you started. Just start up the server in the background, then run the client, and it should send the contents of "in" to "out", over the socket.use IO::Socket; my $server = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => 5050, Proto => 'tcp' ) or die "Can't create client socket: $!"; open FILE, "in"; while (<FILE>) { print $server $_; } close FILE;
You'll probably want to tinker around with it a bit--perhaps put in some command line options for the host and port; make it so that the server handles multiple connections (using IO::Select); etc.
In reply to Re: How do I send a file through a Socket Connection ?
by btrott
in thread How do I send a file through a Socket Connection ?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |