0

I'm trying to send data across machine using Netcat using UDP instead of TCP.

Now, unlike TCP(Netcat over TCP) which used to mark the completion of the file transfer by exiting the nc process, the UDP(Netcat over UDP) process never seem to exit, unless done forcefully using CTRL+C

Example

$ pv upd_mnl_client.rb | nc -u 192.168.1.117 5555

385 B 0:00:00 [39.8kiB/s] [==================================================================>] 100%
^C ## I have to do this because the process never exit

Any Clue what I'm missing above.

Viren
  • 171
  • 1
  • 2
  • 10

2 Answers2

4

You didn't specify --send-only, so it has no way to know whether or not you're done receiving. If you want it to receive data too, then you'll have to tell it when you're done. If you don't want it to receive data, specify --send-only.

David Schwartz
  • 31,449
  • 2
  • 55
  • 84
  • Can you provide me link through this so that I can read through more about it. Since the man [page](http://linux.die.net/man/1/nc) has nothing that explain that. – Viren Nov 25 '15 at 12:43
  • 1
    You can start [here](https://nmap.org/book/ncat-man-misc-options.html) or [here](http://www.pkill.info/linux/man/1-ncat/). – David Schwartz Nov 25 '15 at 12:47
  • @DavidScwartz Thanks. Just one last question though the listening `nc client` has to be started with `--recv-only` correct? or `nc -ul [ip] [port] > upd_mnl_client.rb ` is good enough. – Viren Nov 25 '15 at 12:54
  • I don't think so. You're not expecting the listening program to stop by itself, are you? (How would it know?) – David Schwartz Nov 25 '15 at 12:55
  • I guess I was like it used to work over TCP. – Viren Nov 25 '15 at 12:57
  • 1
    TCP has a way to say "I'm done". UDP doesn't. – David Schwartz Nov 25 '15 at 18:59
0

You might could use the UDP timeout feature for this. For example:

nc -ul -i5 <port>

This will time a UDP listener out after 5 seconds.

warybyte
  • 26
  • 4