I'm trying to test UDP between 2 terminals in the same machine.

For instance:

Terminal 1

  • UDP listener@port:3000
  • UDP sender to port:3001

Terminal 2

  • UDP listener@port:3001
  • UDP sender to port:3000

and testing the above under the environment - MacOSX terminal and Linux Terminal (Android Emulators).

Anyone knows command for this?

I've googled and found nc for UNIX, but for OSX


$ nc                                                                     [~]
usage: nc [-46AcCDdFhklMnOortUuvz] [-K tc] [-b boundif] [-i interval] [-p source_port]
      [-s source_ip_address] [-w timeout] [-X proxy_version]
      [-x proxy_address[:port]] [hostname] [port[s]]

It seems that nc does not have -u option for UDP.

EDIT: I've got answers that suggest the OSX nc does have -u option.

Having said that. Aside from this Question, here's what I've done as the final approarch;

For OSX:

I use node.js instead of Shell commands for these UDP testing. This is much more powerful and comfortable to me.

For Android(Linux):

I prepared a test Android App project to test. Clone the project, and open the identical projects, and run 2 identical instances(emulators).

Just for future references.

  • 1
    I can see a tiny u there: nc [-....u..]
    – zapl
    Jan 30, 2014 at 19:30
  • Thanks. Reading the dev apple page throughly, it's there.
    – Ken OKABE
    Jan 31, 2014 at 3:07

1 Answer 1


OS X's nc does have a -u option, which tells it to use UDP. The only tricky thing is that you have to run two instances of nc -u on each terminal, one sending and one listening; and since one (generally the listener) will be in the background, using control-C to exit it will only exit for foreground instance; you have to kill the background one explicitly. This should do it:

nc -u -l 3000 & nc -u localhost 3001; kill $!

...then just reverse the port numbers on the other terminal. When you kill the foreground (sending) nc, it'll execute the kill $! and clean up the listener as well.


You must log in to answer this question.

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