UDP commands for Linux and Mac?

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

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/nc.1.html

$ 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.

Answers


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.


Need Your Help

Replace umlaute (äüö) for SEO link in rails - best way

ruby-on-rails ruby string seo replace

I'm using the permalink_fu plugin to create permalinks from titles. My problem is: If the title contains german characters, they are just replaced with '_'.

cv::split or Eigen::Stride: Which is more efficient for mapping multi-channel matrices from OpenCV to Eigen structures

c++ opencv eigen

I am mapping a multi-channel OpenCV cv::Mat to a Eigen::Matrix. There are a couple ways I thought of to do it. Ignoring row- vs column-major for the sake of the example, the first is: