-1

I have a bash script:

#!/bin/bash
while :
    do
        nc -l -p 30003 | python3 script.py 
    done

I want that listening works all time.

nc localhost 30003 # works, fine
*type something*
Ctrl+C

Try again nc localhost 30003 # not working

So, after socket closed first time, it never open again..

How can I fix it?

Thanks.

1 Answers1

2

You need to use the -k option with nc, it's in the manual page:

         -k' Forces nc to stay listening for another connection after its current connection is completed. It is an error to use this option without the -l option. 
dawud
  • 15,096
  • 3
  • 42
  • 61