1

I'm trying to use netcat to server some bash command results via a web interface, that stays running. The page is dynamic and needs to be updated upon loading.

Just an example with what I'm using:

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

Unfortunately upon loading the page in a web browser, the page just hangs. If I go into CLI and kill the current connection loop, the page will instantly load.

This is happening on 2 servers but is running just fine on another so I'm finding it odd...

Hauke Laging
  • 90,279
  • Drop the -k option. – Marco Jan 25 '15 at 16:18
  • I originally didn't have -k in the command but found that immediately when my browser connects, netcat stops listening on the port. The issue is still there with or without -k. – Michael Ojeda Jan 25 '15 at 16:40
  • Why should the port be kept open after the message has been sent? It works here as expected when the -k is dropped, no hangs or other issues. – Marco Jan 25 '15 at 17:12
  • Because it needs to be accessible more than once, for whatever reason netcat seems to act differently on this server than on another one so it stops listening without -k but continues listening with it. – Michael Ojeda Jan 25 '15 at 17:49
  • Oddly, enough this appears to only be happening on debian 7u1. Ubuntu it seems to work just fine. – Michael Ojeda Jan 25 '15 at 18:31

1 Answers1

0

Debian 7u1 installs netcat with netcat-traditional which appears to have it's own set of problems, my original issue being one of them.

Removed netcat-traditional by running apt-get remove netcat-traditional and installing the proper one with apt-get install netcat-openbsd everything works as it should!