⭐ in reply to How do I send a file through a Socket Connection ?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Answer: How do I send a file through a Socket Connection ?
by chromatic (Archbishop) on Mar 24, 2000 at 08:40 UTC | |
|
Re: Answer: How do I send a file through a Socket Connection ?
by Valerie170 (Initiate) on Jan 21, 2002 at 21:16 UTC | |
|
Re: Answer: How do I send a file through a Socket Connection ?
by Anonymous Monk on Jan 08, 2003 at 22:17 UTC |