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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



HTTP404
Deleted

Mar 18, 2001, 4:34 AM

Post #1 of 1 (218 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

--------------------------------------
#!/usr/bin/perl
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;

$SIG{CHLD} = \&REAPER;



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