Git Product home page Git Product logo

erlzmq-1's Introduction

Erlang bindings for ZeroMQ

Building

Bindings work against zeromq/ZeroMQ2-x's master branch.

$ git clone [email protected]:zeromq/erlzmq.git
$ cd erlzmq
$ ./bootstrap
$ ./configure --with-zeromq=/path/to/zeromq
$ make

Optionally build the docs:

$ make docs

Usage Samples

  • Sample ZMQ_REQ client
$ erl +K true -smp disable -pa /path/to/zmq/ebin
% Create ZeroMQ context
1> zmq:start_link().
{ok,<0.34.0>}

% Create a ZeroMQ REQ socket and specify that messages
% are delivered to the current shell's mailbox.
2> {ok, S} = zmq:socket(req, [{active, true}]).
{ok,{#Port<0.623>,1}}

% Connect to server
3> zmq:connect(S, "tcp://127.0.0.1:5555").
ok

% Send a message to server
4> zmq:send(S, <<"Test">>).
ok

% Receive a reply
5> zmq:recv(S).
{error,einval}

% Note the error - in the active socket mode we cannot
% receive messages by calling zmq:recv/1. Instead
% use receive keyword to accomplish the task.

6> f(M), receive M -> M end.
% The process blocks because there's no reply from server
% Once you start the server as shown in the following steps
% the receive call returns with the following message:
{zmq,1,<<"Reply">>}
  • Sample ZMQ_REP server

Start another shell either within the same Erlang VM by using ^G, or in a separate OS shell:

$ erl +K true -smp disable -pa /path/to/zmq/ebin
1> zmq:start_link().
{ok,<0.34.0>}
2> {ok, S} = zmq:socket(rep, [{active, false}]).
{ok,{#Port<0.483>,1}}
3> zmq:bind(S, "tcp://127.0.0.1:5555").
ok
4> zmq:recv(S).
{ok,<<"Test">>}
5> zmq:send(S, <<"Reply">>).
ok

You can run a server and any number of clients in the same Erlang shell or on different nodes.

See https://zeromq.github.io/erlzmq/ for more examples and full documentation. (Content is uploaded from doc/index.html).

Updating documentation on GitHub

$ git checkout master   # make sure you are on master branch
$ make gitdocs          # this will update gh-pages branch and commit changes to origin

License

BSD License

Copyright

  • Copyright (c) 2010 Dhammika Pathirana
  • Copywight (c) 2010 Serge Aleynikov

Contact

Copying

Erlang bindings are released under open-source BSD License (see LICENSE file)

erlzmq-1's People

Contributors

saleyn avatar dhammika avatar sustrik avatar benoitc avatar squaremo avatar yrashk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.