Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

Receiving:

nc 127.0.0.1 3000 > /dev/null

Sending:

cat /dev/random | nc 127.0.0.1 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

2 Answers 2

Use nc 127.0.0.1 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 linux.die.net/man/1/nc –  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 127.0.0.1 3000 > /dev/null
share|improve this answer
    
>/dev/null is much shorter. –  ott-- Jul 19 '12 at 19:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.