For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2006 > IO::Socket server









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author IO::Socket server
deadpickle

2006-09-05, 3:57 am

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.

usenet@DavidFilmer.com

2006-09-05, 3:57 am

deadpickle wrote:
> [snip multiposted question]


Don't multipost. It's rude.

(the bot is still offline, but it sent me an e-mail)

--
David Filmer (http://DavidFilmer.com)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com