CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Sockets to OOP Sockets



Mar 18, 2001, 4:34 AM

Post #1 of 1 (351 views)
Sockets to OOP Sockets Can't Post

guys i got for perl webserver, it works fine

but it uses not OOP style of sockets can any1 plz help me to convert it to OOP sockets

BEGIN { $ENV{PATH} = '/' }
use Socket;
use Carp;

sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }

my $port = shift || 25123;
my $proto = getprotobyname('tcp');
socket(Server, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack ("l", 1)) or die
"setsockopt: $!";
bind(Server, sockaddr_in($port, INADDR_ANY)) or die "bind: $!";
listen (Server, SOMAXCONN) or die "listen: $!";

logmsg "server started on port $port";

my $paddr;


for ( ; $paddr = accept(Client, Server); close Client) {
my ($port, $iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr, AF_INET);

logmsg "connection from $name [", inet_ntoa($iaddr), "] at port $port";

my $request = <Client>;
$request =~ s/HTTP.*//g;

my $line;

print Client "<html><head><title>Perl Web Server</title></head>\n";
print Client "<center><u><h1>WOW</h1></u><p>\n";
print Client "<h3>A \"PERL\" based web server!</h3>Very Cool...\n";
print Client "<p>By the way, it appears you said $request </html>";


thnx a lot in advance


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives