Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to test a TCP server by connecting with netcat as a client sending a stream from /dev/random and at the same time pipe the output to /dev/null.


nc 3000 > /dev/null


cat /dev/random | nc 3000

How can I do both at same time?

I can only connect one client and I need to pipe output to /dev/null for fast consumption of the output (~50MB/s).

share|improve this question

Use nc 3000 >/dev/null & to send that command to background. Then you can run the other command. Check the jobs commands as well as fg and bg to see how to switch foreground and background jobs.

share|improve this answer
No, this would not work. I need to send to stdin of netcat and pipe stdout of same netcat process to /dev/null. – JeffV Jul 19 '12 at 12:20
netcat can open only 1 network connection. For a client/server model, you need 2 processes. See the example on the manpage at – ott-- Jul 19 '12 at 13:13
Not looking for more than one connection. In this case server by design is restricted to only one client at a time. Since, the TCP connection is bidirectional, and I am trying to send random bytes to the server while consuming everything it sends to the client as fast as possible. – JeffV Jul 19 '12 at 19:00
Ah, you're looking for the echo service. Check your /etc/inetd.conf or xinetd.conf, echo is usually disabled. chargen is also a nice thing to play with. – ott-- Jul 19 '12 at 19:56

Apparently, this works:

cat /dev/random | netcat 3000 > /dev/null
share|improve this answer
>/dev/null is much shorter. – ott-- Jul 19 '12 at 19:49

You must log in to answer this question.

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