If i run this script and connect to 127.0.0.1 in my browser(s) it serves me the embedded form and accepts and displays the posted data from submitting that form:

#! perl -slw use strict; #use threads; use IO::Socket; $|++; my $page = do{ local $/; <DATA> }; my $s = IO::Socket::INET->new( Listen => 1, LocalPort => 80 ); while( my $c = $s->accept ) { printf "Connection accepted from %s\n", $c->peerhost; # async { my $req = <$c>; printf "Request received: %s\n", $req; my( $act, $url, $mode ) = split ' ', $req; if( $act eq 'GET' ) { if( $url eq '/' ) { print $c $page; } else { print $c '404 Not found'; } } elsif( $act eq 'POST' ) { my $read = 0; print $c '200 OK'; print $c ''; print $req; while( defined( $_ = <$c> ) and length() !=2 ) { printf "%s", $_; $read = $1 if $_ =~ m[Content-Length: (\d+)]; } print "\n", '=' x 20; my $post; read( $c, $post, $read ); print $post; } else { print $c '404 Not found'; } print $c ''; shutdown( $c, 2 ); close $c; # }->detach; } __DATA__ HTTP/1.0 200 OK Date: Mon, 28 Feb 2012 22:38:34 GMT Server: Perl/IOSocket/BrowserUk Content-Length: 3057 Connection: close Content-Type: text/html; charset=iso-8859-1 <html> <head> <title>A test</title> </head> <body> <h4>A test</h4> <p>A test paragraph. <form method=post> select: <select name=select><option value="2">2</option><option value= +"3">2</option><option value="4">4</option><option value="5">5</option +><option value="6">6</option><option value="7">7</option></select> <br />Radio: <input type="radio" name="radio" value="yes" /> Yes <inpu +t type="radio" name="radio" value="no" /> No <br />Radio2: <input type="radio" name="radio2" value="yes" />Yes<inpu +t type="radio" name="radio2" value="no" />No. <br />Select2: <select name=select2><option value="1">1</option><optio +n value="2">2</option><option value="3">3<option><option value="4">4< +/option><option value="5">5</option><option value="6">6</option><opti +on value="7">7</option><option value="8">8</option><option value="9"> +9</option><option value="10">10</option></select> <table border="1"> <tr><th>________</th><th>A</th><th>B</th><th>C</th></tr> <tr> <td>A</td> <td>-</td> <td> <select name="1.2"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td> <select name="1.3"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> </tr> <tr> <td>B</td> <td> <select name="2.1"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td>-</td> <td> <select name="2.3"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> </tr> <tr> <td>C</td> <td> <select name="3.1"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td> <select name="3.2"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td>-</td> </tr> </table> <input type="submit" value="Submit" /> </form> </body> </html>

(Note: this is drastically cut down toward the minimum, (the re-boot and trim cycle is tedious), that displays the following problem.)

However, if I connect to it via my external IP address -- port 80 forwarded to this machine via NAT -- the connect is accepted (at the server end), the browser spins its wheels for a few seconds and then the machine bluescreens! (The only non-hardware related bluescreen I've ever had with this OS.)

This happens regardless of the browser I use -- hence I exclude that.

A 'proper' httpd runs fine on this setup, hence I exclude the tcpip stack, OS etc.

Which brings me back to Perl and my own code. I've disabled the threading to exclude that red-herring from the picture. So that leaves something wrong in my handling of HTTP -- then why would it run fine locally? -- and IO::Socket -- ditto!

So, having excluded everything I can think of, and still having the problem, I throw it open to see what idiocies I am committing?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


In reply to [OT]ish: HTTP/HTML/IO::Socket sanity check. by BrowserUk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.