Netcat Server Connection Refused

JohnMurhy picture JohnMurhy · Apr 27, 2015 · Viewed 10.9k times · Source

Using netcat, I need to create a simple server to respond with simple JSON data.

First I am trying with an HTML page:

while true ; do nc -l 8888  < index.html ; done

or even more simply:

netcat -l 8888 < index.html

And then in my browser I do this:

http://localhost:8888/index.html

I also try to connect using netcat:

nc -vz 127.0.0.1 8888

Each of these yields a 'connection refused' result:

localhost [127.0.0.1] 8888 (ddi-tcp-1): Connection refused

How do I resolve this error?

Answer

JohnMurhy picture JohnMurhy · Apr 27, 2015

The problem was resolved.

I had to use

netcat -l -p 8888 < index.html

This way I can listen to a localport. Now I it is working.