A simple dart zeromq implementation/wrapper around the libzmq C++ library
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)
andsetCurveServerKey(String key)
) - Socket options (
setOption(int option, String value)
) - Receiving multipart messages (
ZMessage
) - Topic subscription for
sub
sockets (subscribe(String topic)
&unsubscribe(String topic)
) - Asynchronous polling using
ZPoller
Currently Windows and Android are officially supported as platforms, but it depends on the used shared library of libzmq
.
I have tested this on Windows and Android, which 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.
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/
)
Note that in order for this plugin to work you will need to either get a shared library of
libzmq
or compile it yourself. Especially when using this on windows you need to make sure thatlibzmq
is compiled usingMSVC-2019
if you are usingclang
it will not work (more info)
Installing libzmq and running dart pub add dartzmq
should be all that is required to use this package in your own application. To also run the example project, follow these steps:
- Install libzmq
- Install flutter (It may be easiest to install from source, otherwise you can follow the snap instructions)
- Update .profile with PATH to /flutter/bin (e.g. export PATH=$PATH:~/src/flutter/bin)
- Ensure ninja-build, clang, and libgtk-3-dev are installed (via apt or other package manager)
- Run
flutter
- Run
flutter config --enable-linux-desktop
- Clone this repo and
cd dartzmq/example
flutter create .
to enable linux desktop for this projectflutter run
- Click the "Send" button and the received message will be displayed as an array of ints
[1,2,3,4,5]
Note that you need to use Android NDK version r21d. Newer versions are currently not supported (see zeromq/libzmq#4276)
- Follow these steps to build a
libzmq.so
for different platforms- If you need
curve
support make sure to set the environment variableCURVE
either toexport CURVE=libsodium
orexport CURVE=tweetnacl
before running the build command
- If you need
- Include these in your project following these steps
- 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
- You can find these inside the Android NDK for example under this path
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]);
Receive ZMessage
s
_socket.messages.listen((message) {
// Do something with message
});
Receive ZFrame
s
_socket.frames.listen((frame) {
// Do something with frame
});
Receive payloads (Uint8List
)
_socket.payloads.listen((payload) {
// Do something with payload
});
Destroy socket
socket.close();
Destroy context
context.stop();