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.

migrated from stackoverflow.com Feb 3 '14 at 23:24

This question came from our site for professional and enthusiast programmers.

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

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.

Your Answer

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

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