bash - Minimal web server using netcat -


i'm trying set minimal web server using netcat (nc). when browser calls localhost:1500, instance, should show result of function (date in example below, it'll python or c program yields data). little netcat web server needs while true loop in bash, possibly simple this:

while true ;  echo -e "http/1.1 200 ok\n\n $(date)" | nc -l -p 1500  ; done 

when try browser shows available data during moment when nc starts. want browser displays data during moment browser requests it, though. how can achieve this?

try this:

while true ; nc -l -p 1500 -c 'echo -e "http/1.1 200 ok\n\n $(date)"'; done 

the -cmakes netcat execute given command in shell, can use echo. if don't need echo, use -e. further information on this, try man nc. note, when using echo there no way program (the date-replacement) browser request. want this:

while true ; nc -l -p 1500 -e /path/to/yourprogram ; done 

where yourprogram must protocol stuff handling get, sending http 200 etc.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -