Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Netcat style utility for ZeroMQ, written in C++

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

zmqcn

zmqcn is a small but powerful command-line interface to ØMQ.

It's written in C++ and was heavily inspired by [https://github.com/zacharyvoase/zmqc]

It allows you to create a socket of a given type, bind or connect it to multiple addresses, set options on it, and receive or send messages over it using standard I/O, in the shell or in scripts. It's useful for debugging and experimenting with most possible network topologies.

Build

make

Usage

zmqcn [-h] -v (-b | -c) address -s SOCK_TYPE -f FILTER -o SOCK_OPT

Mode

-r, --read
Read messages from the socket onto stdout.
-w, --write
Write messages from stdin to the socket.

Behavior

-b, --bind
Bind to the specified address(es).
-c, --connect
Connect to the specified address(es).

Socket Parameters

-s SOCK_TYPE
Which type of socket to create. Must be one of PUSH, PULL, PUB, SUB or PAIR. See man zmq_socket for an explanation of the different types. REQ, REP, DEALER and ROUTER sockets are currently unsupported. --read mode is unsupported for PUB sockets, and --write mode is unsupported for SUB sockets.
-o SOCK_OPT=VALUE
Socket option names and values to set on the created socket. Consult man zmq_setsockopt for a comprehensive list of options. Note that you can safely omit the ZMQ_ prefix from the option name. If the created socket is of type SUB, and no SUBSCRIBE options are given, the socket will automatically be subscribed to everything.
address
One or more addresses to bind/connect to. Must be in full ZMQ format (e.g. tcp://<host>:<port>)

Examples

zmqcn -rc 'tcp://127.0.0.1:5000' -s SUB

Subscribe to tcp://127.0.0.1:5000, reading messages from it and printing them to the console. This will subscribe to all messages by default (you don't need to set an empty SUBSCRIBE option). Alternatively:

zmqcn -r -s SUB -o SUBSCRIBE='com.organization.' -c 'tcp://127.0.0.1:5000'

This will subscribe to all messages starting with com.organization..


ls | zmqcn -wb 'tcp://*:4000' -s PUSH 

Send the name of every file in the current directory as a message from a PUSH socket bound to port 4000 on all interfaces. Don't forget to quote the address to avoid glob expansion.


zmqcn -rc 'tcp://127.0.0.1:5202'  -s PULL | tee $TTY | zmqc -wc 'tcp://127.0.0.1:5404' -s PUSH

Read messages coming from a PUSH socket bound to port 5202 (note that we're connecting with a PULL socket), echo them to the active console, and forward them to a PULL socket bound to port 5404 (so we're connecting with a PUSH).


zmqcn -n 10 -0rb 'tcp://*:4123'  -s PULL | xargs -0 grep 'pattern'

Bind to a PULL socket on port 4123, receive 10 messages from the socket (with each message representing a filename), and grep the files for 'pattern'. The -0 option means messages will be NULL-delimited rather than separated by newlines, so that filenames with spaces in them are not considered two separate arguments by xargs.

LICENSE

This is licensed Apache 2.0. Please read the accompanying LICENSE file.

Something went wrong with that request. Please try again.