Thread overview
ZeroMQ wrapper for D2
Oct 22, 2011
simendsjo
Oct 23, 2011
Kean Forrest
Oct 23, 2011
simendsjo
Oct 23, 2011
simendsjo
Oct 23, 2011
Johannes Pfau
Oct 23, 2011
simendsjo
Oct 25, 2011
Johannes Pfau
October 22, 2011
I saw someone mention ZeroMQ in a subthread the other day. I watched a few videos, and it looks to me like a good fit for D. The philosophies matches pretty well: small, clean api, no bloat (only transport, no protocols), very flexible setup/usage and message passing for communication.

Someone with experience with D and zmq could probably finish a good wrapper in a couple of days.

The D binding on their website is for v2.1 using D1 and tango, so I hacked together a wrapper for 3.0.2 with several examples from the guide. Hopefully this hack motivates someone to write a complete wrapper.

http://dl.dropbox.com/u/36543537/dzmq.zip

zmq.d = zmq.h translation
dzmq.d = d-ified wrapper
zguide-examples/* = translated examples from the guide.

It's only tested on windows, and the .lib and .dll is included in the archive. Shouldn't be much problems running on linux either though, but you'll have to download zmq from github.
October 23, 2011
On 22/10/11 23:24, simendsjo wrote:
> I saw someone mention ZeroMQ in a subthread the other day. I watched a
> few videos, and it looks to me like a good fit for D. The philosophies
> matches pretty well: small, clean api, no bloat (only transport, no
> protocols), very flexible setup/usage and message passing for
> communication.

+1

ZMQ seems almost too good, I never knew it existed. If D had this as a networking/concurrency method it would be a huge plus AFAIK.

This wrapper (2.1.10 stable) is closer to the python version:

http://min.us/lOZ88QxPWyB6q

Hello world:

import zmq.zmq;
import std.stdio;
void main()
{
    auto ctx = new Context();
    version(client)
    {
        auto sock = ctx.socket(ZMQ_REQ);
        sock.connect("tcp://localhost:5555");
        sock.send("hello");
        writeln(sock.recv!string);
    }
    else
    {
        auto sock = ctx.socket(ZMQ_REP);
        sock.bind("tcp://*:5555");
        writeln(sock.recv!string);
        sock.send("world");
    }
}
October 23, 2011
simendsjo wrote:
>I saw someone mention ZeroMQ in a subthread the other day. I watched a few videos, and it looks to me like a good fit for D. The philosophies matches pretty well: small, clean api, no bloat (only transport, no protocols), very flexible setup/usage and message passing for communication.
>
>Someone with experience with D and zmq could probably finish a good wrapper in a couple of days.
>
>The D binding on their website is for v2.1 using D1 and tango, so I hacked together a wrapper for 3.0.2 with several examples from the guide. Hopefully this hack motivates someone to write a complete wrapper.
>
>http://dl.dropbox.com/u/36543537/dzmq.zip
>
>zmq.d = zmq.h translation
>dzmq.d = d-ified wrapper
>zguide-examples/* = translated examples from the guide.
>
>It's only tested on windows, and the .lib and .dll is included in the archive. Shouldn't be much problems running on linux either though, but you'll have to download zmq from github.

Have you thought about submitting the zmq.d file to deimos? https://github.com/D-Programming-Language/deimos

That would probably boost it's publicity in the D community.

-- 
Johannes Pfau

October 23, 2011
On 23.10.2011 14:47, Johannes Pfau wrote:
> simendsjo wrote:
>> I saw someone mention ZeroMQ in a subthread the other day. I watched a
>> few videos, and it looks to me like a good fit for D. The philosophies
>> matches pretty well: small, clean api, no bloat (only transport, no
>> protocols), very flexible setup/usage and message passing for
>> communication.
>>
>> Someone with experience with D and zmq could probably finish a good
>> wrapper in a couple of days.
>>
>> The D binding on their website is for v2.1 using D1 and tango, so I
>> hacked together a wrapper for 3.0.2 with several examples from the
>> guide. Hopefully this hack motivates someone to write a complete
>> wrapper.
>>
>> http://dl.dropbox.com/u/36543537/dzmq.zip
>>
>> zmq.d = zmq.h translation
>> dzmq.d = d-ified wrapper
>> zguide-examples/* = translated examples from the guide.
>>
>> It's only tested on windows, and the .lib and .dll is included in the
>> archive. Shouldn't be much problems running on linux either though,
>> but you'll have to download zmq from github.
>
> Have you thought about submitting the zmq.d file to deimos?
> https://github.com/D-Programming-Language/deimos
>
> That would probably boost it's publicity in the D community.
>

Not sure how we should handle versioning. This is a translation of the unstable 3.0.2. We should also have the stable version there.

October 23, 2011
On 23.10.2011 14:25, Kean Forrest wrote:
> On 22/10/11 23:24, simendsjo wrote:
>> I saw someone mention ZeroMQ in a subthread the other day. I watched a
>> few videos, and it looks to me like a good fit for D. The philosophies
>> matches pretty well: small, clean api, no bloat (only transport, no
>> protocols), very flexible setup/usage and message passing for
>> communication.
>
> +1
>
> ZMQ seems almost too good, I never knew it existed. If D had this as a
> networking/concurrency method it would be a huge plus AFAIK.

Agreed. IPC doesn't work on windows though. Not sure if this could/should be simulated to some degree.

> This wrapper (2.1.10 stable) is closer to the python version:
>
> http://min.us/lOZ88QxPWyB6q
>
> Hello world:
>
> import zmq.zmq;
> import std.stdio;
> void main()
> {
> auto ctx = new Context();
> version(client)
> {
> auto sock = ctx.socket(ZMQ_REQ);
> sock.connect("tcp://localhost:5555");
> sock.send("hello");
> writeln(sock.recv!string);
> }
> else
> {
> auto sock = ctx.socket(ZMQ_REP);
> sock.bind("tcp://*:5555");
> writeln(sock.recv!string);
> sock.send("world");
> }
> }

Pretty similar to what I did. Zeromq's porting guide recommend using available language features and naming standards, so I added a default context using shared and module ctor/dtor's and named enums according to phobos rules. Already found some bugs with my wrapper though :)

version(client)
{
  auto sock = connect("tcp://localhost:5555", SocketType.request);
  sock.send("hello");
  writeln(sock.receive!string());
}
else
{
  auto sock = bind("tcp://*:5555");
  writeln(sock.receive!string());
  sock.send("world");
}

The default context is only created on the first call to connect/bind, so you can avoid this and write it as:
auto ctx = new Context();
auto sock = ctx.create(SocketType.request);
...

I'm in the process of porting more of the examples to my wrapper to see how it holds up. I'll post updated code once I get a little further.
But I really don't know enough D or zmq to write a good wrapper. It would be great if you (or someone else) could write a wrapper.
October 23, 2011
On 23.10.2011 14:25, Kean Forrest wrote:
>
> ZMQ seems almost too good, I never knew it existed. If D had this as a
> networking/concurrency method it would be a huge plus AFAIK.

Together with std.parallelism, std.concurrency and the upcoming Thrift implementation this makes D quite capable for writing high-performance distributed applications.
October 25, 2011
simendsjo wrote:
>On 23.10.2011 14:47, Johannes Pfau wrote:
>> simendsjo wrote:
>>> I saw someone mention ZeroMQ in a subthread the other day. I watched a few videos, and it looks to me like a good fit for D. The philosophies matches pretty well: small, clean api, no bloat (only transport, no protocols), very flexible setup/usage and message passing for communication.
>>>
>>> Someone with experience with D and zmq could probably finish a good wrapper in a couple of days.
>>>
>>> The D binding on their website is for v2.1 using D1 and tango, so I hacked together a wrapper for 3.0.2 with several examples from the guide. Hopefully this hack motivates someone to write a complete wrapper.
>>>
>>> http://dl.dropbox.com/u/36543537/dzmq.zip
>>>
>>> zmq.d = zmq.h translation
>>> dzmq.d = d-ified wrapper
>>> zguide-examples/* = translated examples from the guide.
>>>
>>> It's only tested on windows, and the .lib and .dll is included in the archive. Shouldn't be much problems running on linux either though, but you'll have to download zmq from github.
>>
>> Have you thought about submitting the zmq.d file to deimos? https://github.com/D-Programming-Language/deimos
>>
>> That would probably boost it's publicity in the D community.
>>
>
>Not sure how we should handle versioning. This is a translation of the unstable 3.0.2. We should also have the stable version there.
>

seems like that's currently being discussed here: https://github.com/D-Programming-Language/deimos/commit/65acb7bc0ad63649485b207ede9a59f6fcc95b61#comments

-- 
Johannes Pfau