# Netcat never ending http connection



## mojeda (Jan 24, 2015)

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"...


----------



## mojeda (Jan 24, 2015)

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.


----------



## Wintereise (Jan 25, 2015)

Why use netcat at all for this, wouldn't embedded httpds be better if resource usage is a concern?


----------



## mojeda (Jan 25, 2015)

Wintereise said:


> 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.


----------



## Wintereise (Jan 25, 2015)

I use Sprunge for that (http://sprunge.us/)


----------



## mojeda (Jan 25, 2015)

Wintereise said:


> I use Sprunge for that (http://sprunge.us/)


Not viable.


----------



## mojeda (Jan 25, 2015)

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!


----------

