Code Monkey home page Code Monkey logo

dartzmq's Introduction

Discord GitHub tag (latest by date)

dartzmq

A simple dart zeromq implementation/wrapper around the libzmq C++ library

Features

Currently supported:

  • Creating sockets (pair, pub, sub, req, rep, dealer, router, pull, push, xPub, xSub, stream)
  • Sending messages (of type List<int>)
  • Bind (bind(String address))
  • Connect (connect(String address))
  • Curve (setCurvePublicKey(String key), setCurveSecretKey(String key) and setCurveServerKey(String key))
  • Socket options (setOption(int option, String value))
  • Receiving multipart messages (ZMessage)
  • Topic subscription for sub sockets (subscribe(String topic) & unsubscribe(String topic))
  • Monitoring socket states (ZMonitor & MonitoredZSocket)

Getting started

Currently Windows and Android are officially supported as platforms. Basically there a no extra setup steps unless the provided zeromq binary does not work for your platform. I have tested this on Windows and Android, which both work. Other platforms have not been tested, but should work. If you have tested this plugin on another platform and got it to work, please share your steps and create an issue so I can add it to the list below.

Usage

Create context

final ZContext context = ZContext();

Create socket

final ZSocket socket = context.createSocket(SocketType.req);

Connect socket

socket.connect("tcp://localhost:5566");

Send message

socket.send([1, 2, 3, 4, 5]);
socket.sendString('My Message');

Receive ZMessages

socket.messages.listen((message) {
    // Do something with message
});

Receive ZFrames

socket.frames.listen((frame) {
    // Do something with frame
});

Receive payloads (Uint8List)

socket.payloads.listen((payload) {
    // Do something with payload
});

Receive socket events

final MonitoredZSocket socket = context.createMonitoredSocket(SocketType.req);
socket.events.listen((event) {
    log('Received event ${event.event} with value ${event.value}');
});
final ZSocket socket = context.createSocket(SocketType.req);
final ZMonitor monitor = ZMonitor(
    context: context,
    socket: socket,
    event: ZMQ_EVENT_CONNECTED | ZMQ_EVENT_CLOSED, // Only listen for connected and closed events
);
monitor.events.listen((event) {
    log('Received event ${event.event} with value ${event.value}');
});

Destroy socket

socket.close();

Destroy monitor

monitor.close();

Destroy context

context.stop();

Using a custom libzmq binary

Windows

Place a shared library of libzmq next to your executable (for example place libzmq-v142-mt-4_3_5.dll in the folder yourproject/build/windows/runner/Debug/)

You can use a shared library of libzmq or compile it yourself. Especially when using this on windows you need to make sure that libzmq is compiled using MSVC-2019 if you are using clang it will not work (more info)

Android

Note that you need to use Android NDK version r21d. Newer versions are currently not supported (see zeromq/libzmq#4276)

  1. Follow these steps to build a libzmq.so for different platforms
    • If you need curve support make sure to set the environment variable CURVE either to export CURVE=libsodium or export CURVE=tweetnacl before running the build command
  2. Include these in your project following these steps
  3. Include the compiled standard c++ library libc++_shared.so files located inside the Android NDK as in step 2 (reference)
    • You can find these inside the Android NDK for example under this path ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\lib

dartzmq's People

Contributors

enwi avatar

Watchers

 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.