D
deadpickle
This is what I got:
server.pl
use strict;
use IO::Socket;
my $sock = new IO::Socket::INET(
LocalHost => 'localhost',
LocalPort => 7890,
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
$sock or die "no socket :$!";
my($new_sock, $c_addr, $buf);
while (($new_sock, $c_addr) = $sock->accept()) {
my ($client_port, $c_ip) =
sockaddr_in($c_addr);
my $client_ipnum = inet_ntoa($c_ip);
my $client_host =
gethostbyaddr($c_ip, AF_INET);
print "got a connection from: $client_host",
" [$client_ipnum]\n";
while (defined ($buf = <$new_sock>)) {
print $buf;
}
}
client.pl
use strict;
use IO::Socket;
my $file =
my $host = shift || 'localhost';
my $port = shift || 7890;
my $sock = new IO::Socket::INET(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp');
$sock or die "no socket :$!";
What I want it to do is have the server on one computer and the client
on the other. I want the client to connect to the server and request a
file. I want the server to send the file to the client. Its a simple
text file so its not very large. I want it to do this over again until
it is closed. I dont know much about perl programming so any help would
be very appriciated.
server.pl
use strict;
use IO::Socket;
my $sock = new IO::Socket::INET(
LocalHost => 'localhost',
LocalPort => 7890,
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
$sock or die "no socket :$!";
my($new_sock, $c_addr, $buf);
while (($new_sock, $c_addr) = $sock->accept()) {
my ($client_port, $c_ip) =
sockaddr_in($c_addr);
my $client_ipnum = inet_ntoa($c_ip);
my $client_host =
gethostbyaddr($c_ip, AF_INET);
print "got a connection from: $client_host",
" [$client_ipnum]\n";
while (defined ($buf = <$new_sock>)) {
print $buf;
}
}
client.pl
use strict;
use IO::Socket;
my $file =
my $host = shift || 'localhost';
my $port = shift || 7890;
my $sock = new IO::Socket::INET(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp');
$sock or die "no socket :$!";
What I want it to do is have the server on one computer and the client
on the other. I want the client to connect to the server and request a
file. I want the server to send the file to the client. Its a simple
text file so its not very large. I want it to do this over again until
it is closed. I dont know much about perl programming so any help would
be very appriciated.