Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: local webserver for CGI on linux

by my_nihilist (Sexton)
on Sep 19, 2008 at 18:17 UTC ( #712572=note: print w/ replies, xml ) Need Help??


in reply to Re: local webserver for CGI on linux
in thread local webserver for CGI on linux

Was there a perl question in there somewhere?

By "write" I meant "in perl". Consider it a learning experience. Also, all I need is something that will run scripts from a cgi-bin locally based on a singular, established connection. Having never used apache, I figured that by the time I understand it I could have written something to do this (in perl).

This is what I have so far based on various examples:

#!/usr/bin/perl -w use strict; # simple server use Socket; use IO::Handle; socket(SERV, PF_UNIX, SOCK_STREAM,0); unlink "/tmp/testsock"; bind(SERV,sockaddr_un("/tmp/testsock")) or print "ERROR!"; listen(SERV,1); while (accept(CLIENT,SERV)) { CLIENT->autoflush(1); print CLIENT "Hi there!\n"; my $answer = <CLIENT>; print $answer; }
and
#!/usr/bin/perl -w use strict; # simple client use Socket; use IO::Handle; socket(TSOCK, PF_UNIX, SOCK_STREAM,0); connect(TSOCK, sockaddr_un("/tmp/testsock")) or print("ERROR!"); while (defined(my $messg = <TSOCK>)) { print $messg; print TSOCK "Hello server!"; TSOCK->flush; }
This works to the point where the server should recieve and print the answer from the client -- it doesn't. The initial "Hi there!" is recieved and printed tho. Once I can get back and forth communication working, I should be able to figure out what to do next.

Being kind of a luddite, I preferred not to use IO::Socket for the learning experiment.


Comment on Re^2: local webserver for CGI on linux
Select or Download Code
Re^3: local webserver for CGI on linux
by Illuminatus (Curate) on Sep 19, 2008 at 18:45 UTC
    This is not a web-server. It's just socket communication. Your program probably does not work because there is no linefeed in the "Hello server!". Even though you flushed, your server-side read is looking for the linefeed.

    If your communication is across systems, look at inetd/xinetd. There is plenty of documentation on them, and they are very easy to use.

Re^3: local webserver for CGI on linux
by chromatic (Archbishop) on Sep 19, 2008 at 21:59 UTC
    Having never used apache, I figured that by the time I understand it I could have written something to do this (in perl).

    Reading and understanding enough of RFC 2616 (for example) to implement your own web server effectively will take more time than installing and configuring Apache httpd through XAMPP or any decent modern free Unix-like system.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://712572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-18 00:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls