OCaml bindings for ZeroMQ
- C 60.6%
- OCaml 38.1%
- Makefile 1.3%
| .gitignore | ||
| _tags | ||
| libozmqw.clib | ||
| Makefile | ||
| META | ||
| myocamlbuild.ml | ||
| ozmq.mldylib | ||
| ozmq.mllib | ||
| README.md | ||
| tests.ml | ||
| zmq.ml | ||
| zmq.mli | ||
| zmq_ocaml_wrapper.c | ||
OCaml bindings for ZeroMQ
Merge of :
Pre-requisites
License
GNU General Public License.
Install
$ make
$ make tests
$ make install # using ocamlfind
Usage
#use "topfind";;
#require "ozmq";;
(* create a zmq context *)
let ctx = Zmq.ctx_new ();;
(* create sockets *)
let push = Zmq.socket ctx Zmq.PUSH;;
let pull = Zmq.socket ctx Zmq.PULL;;
(* bind and connect sockets *)
Zmq.bind push "inproc://foo";;
Zmq.connect pull "inproc://foo";;
(* send and receive messages *)
Zmq.send push "Hello world!";;
Zmq.receive pull;;
(* send and receive multi-parts messages *)
Zmq.send_multiparts push ["Hello"; "world"; "!"];;
Zmq.receive_multiparts pull;;
(* send and receive messages unless this would block *)
assert (Zmq.send_nowait push "Hello world!");;
assert (Zmq.receive_nowait pull = Some "Hello world!");;
assert (Zmq.receive_nowait pull = None);;
assert (Zmq.send_multiparts_nowait push ["Hello"; "world"; "!"]);;
assert (Zmq.receive_multiparts_nowait pull = ["Hello"; "world"; "!"]);;
assert (Zmq.receive_multiparts_nowait pull = []);;
(* close sockets and term *)
Zmq.close push;;
Zmq.close pull;;
Zmq.ctx_destroy ctx;;