I am trying to do something like:

echo "request" | nc -u 9999 > response.txt

I can see that response is coming from server (with tcpdump) after executing this line.

However, my response.txt stays empty.

Is there a way to get it?

  • Do you have a firewall? Seeing the packet via tcpdump doesn't mean that it will be accepted. – Zoredache Apr 3 '10 at 1:07

Netcat starts "talking" UDP (default is TCP) by specifying the -u command line option. Here's an example of connecting to an RFC 867 time server using UDP. Note the IP address or DNS name of the other host is specified first and the port number is specified second - just like most telnet programs. After the connection is made you'll probably need to press the Enter key to get the time server to send you the current time. (maybe this is your problem)

nc -u igor.alcpress.com 13

Thu Sep 15 14:41:57 2005

Since UDP is not a connection-oriented protocol, the connection will remain "open" until you terminate the program by pressing Ctrl-C.


Does it reply if you don't redirect output ?
try : echo "request" | nc -u 9999 | tee response.txt

  • Hello and thanks for your reply. The command sequence the way you wrote it exits right after its' execution on my machine. However the problem is solved for me. I didn't know I could just run nc -u 9999, and send/receive data inside nc while its running. Thanks a lot once again – user39593 Apr 3 '10 at 1:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy