Netcat never ending http connection

mojeda

New Member
I've got a script to server a basic web page using netcat:


#!/bin/bash

while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; echo -e "Hello World"; } | nc -l -p 8888; done


On one server running the exact same script, the page will load instantly, however on another server the page continuously keeps trying to load until I go into the CLI and CTRL+C the current loop, and then the browser will immediately show "Hello World".

Refreshing the page will do the same thing and doing CTRL+C allows Hello World to show up.

Any netcat wizards that might know why this is happening? Both servers are running the same version.

Edit:

From what I can tell, the instant the web page loads, net cat stops listening on the port but is still "running"...
 
Last edited by a moderator:

mojeda

New Member
Added -k to the command, and while netcat continues to listen the issue where the page never loads until I CTRL+C is still there.
 

mojeda

New Member
Why use netcat at all for this, wouldn't embedded httpds be better if resource usage is a concern?
The main reason is to easily send results of a linux command without having to write to a file and send it off somehow.

This was the only solution I could find that easily allows that.
 

mojeda

New Member
Welp found that the issue was not apparent on Ubuntu but on Debian 7u1(at least). Then I realised netcat-traditional was being installed where netcat-openbsd appears to be the one that works. So problem solved!
 
Top