Implementing a test server using netcat


Whenever you need to test an application that sends and receives data through tcp sockets and don't have enough time to build a server or don't feel the need for a server because anything that would bounce socket data back is sufficient, try using netcat with a pipe. This is the solution I still use today when I need a simple and fast way to test if the data sent from the application is correct:

On the server side:

Create a pipe in the filesystem with 'mknod' and send its contents to netcat.
netcat is listening at port 12345 and writing whatever it receives to the pipe.

$ mknod pipe p
$ cat pipe | nc -l -p 12345 > pipe

For the client side launch your application. I'll demonstrate it using telnet:

$ telnet localhost 12345

Connected to localhost.localdomain (
Escape character is '^]'.
Testing 12345
Testing 12345
Hello World!
Hello World!

That's all. I hope this information is helpful!

Published on Thursday 2011/01/13, last modified on Thursday 2012/02/23