Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
    0: #!/usr/bin/perl -w
    1: # pocketgopher - an RFC-1436 compliant gopher server in < 1024B
    2: # Beth Skwarecki 2004
    3: # This program is free software under the GNU GPL
    4: use strict;
    5: use IO::Socket;
    6: local $/ = "\015\012";
    7: 
    8: #### CONFIGURATION
    9: my $port = '7070';
    10: my $root = '/home/beth/gopher/gopher';
    11: #### THAT IS ALL
    12: 
    13: chroot $root or die "can't chroot: $!\n";
    14: 
    15: # fork
    16: local $SIG{HUP} = 'IGNORE';
    17: exit if (my $pid = fork); 
    18: 
    19: 
    20: # listen
    21: my $sock = new IO::Socket::INET
    22: (LocalPort => $port,
    23:  Type => SOCK_STREAM,
    24:  Listen => 1,
    25:  Reuse => 1
    26: ) or die "Couldn't create socket: $!\n";
    27: 
    28: 
    29: # serve
    30: my $s = $sock->accept();
    31: while(my $req = <$s>){
    32: 
    33:   chomp (my $req = shift);
    34:   $req = '/'.$req;
    35: 
    36:   &error unless (-r $req);
    37:   $req .= '/.cache' if ( -d _ );
    38:   printfile($req);
    39:   close($sock);
    40: }
    41: 
    42: 
    43: sub printfile {
    44:   open (FILE, shift);
    45:   binmode FILE;
    46:   print $s <FILE>;
    47:   close FILE;
    48: }
    49: 
    50: sub error {
    51:     my $req = shift;
    52:   print $s "iBad Request: $! \tfake\t(NULL)\t0".$/;
    53: }
    54: 
    55: 
    56: ----------------------------
    57: (code is over, notes follow)
    58: 
    59: 2004-05-12: 
    60: - changed $/ to \015\012 (thanks revdiablo)
    61: - did a binmode() on the filehandle (thanks Corion)
    62: 
    63: These changes improve things to serve gopher clients on 
    64: different platforms; however, the code still assumes that 
    65: the server is running on a unix-oid OS.
    66: 
    

In reply to gopher server in < 1024B by beth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (16)
    As of 2014-09-17 13:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (81 votes), past polls