0

I'm testing an application using netcat (nc) and I'm getting very low throughput on network connections. When I ran netstat -tnpo I see numerous TCP sessions in TIME_WAIT. I'm sending data to my application via a bash script as indicated below:

while true; do
    echo "<required string>" | nc server_ip port
done

If I instead do this at the terminal:

nc server_ip port
<required string>

the connection terminates immediately and there is no TCP session left in TIME_WAIT.

Why the difference? What do I need to do differently to ensure that after each echo, no TCP port is left in TIME_WAIT?

2
  • Pass it --send-only, I think. Jan 7, 2016 at 5:38
  • Hmmm - my version of netcat (netcat-openbsd 1.105-7ubuntu1) doesn't have that option.
    – AnthonyK
    Jan 7, 2016 at 6:16

1 Answer 1

-1

You may want to use it like this.

    while true; do
        echo "<required string>" | nc server_ip port < /dev/null   
    done

Apologies I don't have enough repo to post it like a comment.

2
  • What's the point of both piping something to nc and redirecting its input from /dev/null? Jan 7, 2016 at 5:39
  • @tollboy Same result anyway
    – AnthonyK
    Jan 7, 2016 at 6:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .