Git Product home page Git Product logo

dartzmq's Introduction

enwi's GitHub stats enwi's top languages

dartzmq's People

Contributors

augustbering avatar enwi avatar jsyrd avatar wajahat414 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dartzmq's Issues

run in android failed.

Failed to load dynamic library 'liblibzmq-v142-mt-4_3_5.so': dlopen failed: library "liblibzmq-v142-mt-4_3_5.so" not found

Question: How to receive string message with subscription?

Question
At the moment I try to use your library for a pub/sub setup.
I try to get string messages of my python publisher.
If I try to write a subscriber with your dart library I have problems to get out the message as string.
I tried your provided example too. But there I have the same problem... I do not get the string message, instead of a string I get some ZFrame...
Can you help me with my problem? (Look at "To Reproduce")
Thank you!

Setup with python publisher and subscriber:
Publisher:

import zmq
import random
import sys
import time

port = "6555"
if len(sys.argv) > 1:
    port = sys.argv[1]
    int(port)

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:%s" % port)

while True:
    # Receives a string format message
    socket.send_string("ML hello")
    time.sleep(1)

Subscriber:

# simple_sub.py
import zmq

host = "127.0.0.1"
port = "6555"

# Creates a socket instance
context = zmq.Context()
socket = context.socket(zmq.SUB)

# Connects to a bound socket
socket.connect("tcp://{}:{}".format(host, port))

# Subscribes to all topics
socket.subscribe("ML")

while True:
    # Receives a string format message
    whole_message = socket.recv_string()
    topic, actual_message = whole_message.split(" ")
    print(actual_message)

Environment
OS: Archlinux 6.0.12-arch1-1
Android x86 emulator: Pixel 5 API 30
flutter: 3.3.9
compileSdkVersion 33
ndkVersion flutter.ndkVersion

To Reproduce
Subscriber with dart:

    // Tst
    final ZContext context = ZContext();
    final ZSocket socket = context.createSocket(SocketType.sub);
    late StreamSubscription _subscription;
    socket.connect("tcp://192.168.178.26:6555");
    socket.subscribe("ML");

    _subscription = socket.messages.listen((message) {
      print(message.toString());
    });

Output:

I/flutter (31175): ZMessage[ZFrame[[77, 76, 32, 104, 101, 108, 108, 111]]]

Brain-free installation

I know it's kind of a huge task, but would it be theoretically possible to use ZeroMQ in Flutter without thinking about Android/Windows/iOS/Linux?

What steps would be necessary?

Would it be possible to distribute precompiled zeromq-Versions (.dll, .so etc) within this plugin?

Is it theoretically possible to transpile the ZeroMQ Code to Dart only?

We think this is an amazing plugin but we're really uncertain about the fact that you need to make sure that e.g. a precompiled .dll (windows) works on every machine (it does not).

EINTR: The operation was interrupted

On Android, I use
socket.send(result);
socket.recv();
An error will be reported
E/flutter (18544): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ZeroMQException(4): EINTR: The operation was interrupted
E/flutter (18544): #0 _checkErrorCode (package:dartzmq/src/exception.dart:56:5)
E/flutter (18544): #1 _checkReturnCode (package:dartzmq/src/exception.dart:49:5)
E/flutter (18544): #2 ZSyncSocket.recv (package:dartzmq/src/socket.dart:406:9)
E/flutter (18544): #3 _FirmwareBodyWidgetState._sendNextMessage (package:healthy_voice/ui/config/firmware_version.dart:179:18)

on ios socket.recv(); Cannot set timeout

when i use
socket.messages.listen((message) {
print('Received: $message');
// _sendNextMessage();
});

An error will be reported
E/flutter (18544): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ZeroMQException(156384763): Operation cannot be accomplished in current state
E/flutter (18544): #0 _checkErrorCode (package:dartzmq/src/exception.dart:56:5)
E/flutter (18544): #1 _checkReturnCode (package:dartzmq/src/exception.dart:49:5)
E/flutter (18544): #2 ZContext._poll (package:dartzmq/src/zeromq.dart:109:9)
E/flutter (18544): #3 ZContext._startPolling. (package:dartzmq/src/zeromq.dart:68:70)
E/flutter (18544): #4 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (18544): #5 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (18544): #6 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

ZeroMQ seems to "wait" one second before receiving data.

Hello there,

I'm testing this feature on windows.
When using a push/pull or pub/sub pattern there seems to be a one second delay on the pull/sub socket.
Is it built into ZeroMQ or can i configure this behaviour?

Best regards

send non-binary data

Hi, why socket.send() parameter is from List<int> type? does it get data as binary array? what if someone wants to send data non-binary?

and I have another question; how we can receive response from a req socket connection?

Not Working For Android Real Device, But Working on Emulator,

[dartzmq] Failed to load library zmq: Invalid argument(s): Failed to load dynamic library 'libzmq.so': dlopen failed: cannot locate symbol "__aarch64_ldadd4_relax" referenced by "/data/app/~~MjLexgoFe5RqnQkIAbG4Cg==/com.example.trader-BdFk7vHBEbrjTXe0LKQ4MA==/lib/arm64/libzmq.so"...
[dartzmq] Failed to load library libzmq: Invalid argument(s): Failed to load dynamic library 'liblibzmq.so': dlopen failed: library "liblibzmq.so" not found
[dartzmq] Failed to load library libzmq-v142-mt-4_3_5: Invalid argument(s): Failed to load dynamic library 'liblibzmq-v142-mt-4_3_5.so': dlopen failed: library "liblibzmq-v142-mt-4_3_5.so" not found

Incomplete data received by sub

hi, did you find a problem? When subscribing to a topic under TCP protocol, big data will accept incompleteness, and I failed to set relevant properties.

Error when i Bind Or Connect With UDP Protocol (ZeroMQException(156384764): The protocol is not compatible with the socket type)

i use SocketType.sub and SocketType.pub to connect and bind from udp address
i watched documentation of zmq and i must use socket type as like Radio and Dish but i can't find it in dartzmq

my simple code like this :


import 'dart:io';

import 'package:dartzmq/dartzmq.dart';

void dishRadioDart() async {
  String udpAddress = "udp://127.0.0.1:5566";
  final context = ZContext();
  final dishSocket = context.createSocket(SocketType.pub);
  final radioSocket = context.createSocket(SocketType.sub);

  try {
    dishSocket.bind(udpAddress);
    print("dish socket binded to address : ${udpAddress}");
    radioSocket.connect(udpAddress);
    print("radio socket connect to address : ${udpAddress}");
    radioSocket.setOption(ZMQ_SUBSCRIBE, "");

    radioSocket.payloads.listen((event) {
      print("received message");
      print("received message is : ${event}");
    });
    while (true) {
      print("send message ");
      dishSocket.sendString("abdullah message ");
      sleep(const Duration(seconds: 1));
    }
  } catch (e) {
    print("error e : ${e}");
  }
}

Received messages are buffered

Messages produced by a server at say 4 hz, will be batched such that 4 messages are received every second. If I change the server to produce at 10hz, I get 10 messages received in a batch every second. I verified this happens regardless if I use a dealer/dealer or pub/sub connection type. I also, verified this happens with a server written in Julia (instead of Python). This seems to be something unique to the dart ZMQ client as it doesn't happen when I used Julia or Python clients.

Here is the output from the Dart code (below). It shows the batching of messages:

image

Here is the important part of the Dart code:


class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  final ZContext _context = ZContext();
  late final ZSocket _socket;
  late StreamSubscription _subscription;
  String _receivedData = '';
  DateTime ? lastTime = null;

 @override
  void initState() {
    _socket = _context.createSocket(SocketType.dealer);
    _socket.connect("tcp://localhost:4482");

    // listen for messages
    _subscription = _socket.messages.listen((msg) {
      _receivedData = msg.toString();
      var now = DateTime.now();
      if (lastTime != null) {
        var diff = now.difference(lastTime!);
        print("msg received  timing = $diff");
      }
      lastTime = now;
      setState(() {
      });
    });
    super.initState();
  }

Here is the entire server Python code:

import zmq
import time

context = zmq.Context()
socket = context.socket(zmq.DEALER)
socket.set(zmq.LINGER, 0)
address = "tcp://*:4482"
socket.bind(address)

print("Running...")
try:
    last_time = None
    while True:
        time.sleep(.25)
        try:
          socket.send_string("test", zmq.NOBLOCK)
          now = time.time()
          if last_time is not None:
            print(f"Sent message.  timing = {now - last_time}")
          last_time = now
        except Exception as e:
            pass
finally:
    socket.unbind(address)  # ALWAYS RELEASE PORT
    socket.close()  # ALWAYS RELEASE RESOURCES
    context.term()  # ALWAYS RELEASE RESOURCES

Am I doing something wrong? Would love to get this fixed! Willing to help!

Fails to load .so libary on linux desktop

Launching lib/main.dart on Linux in debug mode...
Building Linux application...
Debug service listening on ws://127.0.0.1:37089/w-K6VIMgRmg=/ws
Syncing files to device Linux...
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Exception: Could not load any zeromq library
#0      ZContext._initBindings (package:dartzmq/src/zeromq.dart:77:7)
#1      new ZContext (package:dartzmq/src/zeromq.dart:66:5)
#2      main (package:remote_volume_control/main.dart:6:28)
#3      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:130:25)
#4      _rootRun (dart:async/zone.dart:1426:13)
#5      _CustomZone.run (dart:async/zone.dart:1328:19)
#6      _runZoned (dart:async/zone.dart:1861:10)
#7      runZonedGuarded (dart:async/zone.dart:1849:12)
#8      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:126:5)
#9      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

[dartzmq] Failed to load library zmq:  Invalid argument(s): Failed to lookup symbol 'zmq_poller_new': /lib64/libzmq.so: undefined symbol: zmq_poller_new
[dartzmq] Failed to load library libzmq:  Invalid argument(s): Failed to load dynamic library 'liblibzmq.so': liblibzmq.so: cannot open shared object file: No such file or directory
[dartzmq] Failed to load library libzmq-v142-mt-4_3_5:  Invalid argument(s): Failed to load dynamic library 'liblibzmq-v142-mt-4_3_5.so': liblibzmq-v142-mt-4_3_5.so: cannot open shared object file: No such file or directory

--------------------------------------------------

sean@sean-fedora /lib64> ls | grep libzmq
libzmq.so
libzmq.so.5
libzmq.so.5.2.4

not entirely sure whats going on here the code is looking in the right place. any help would be appreciated

Issues with library loading on Windows

When trying to use any these functions in my own code and the example code provided by this package, I'm having getting errors saying there are errors with loading the DLLs.

[dartzmq] Failed to load library zmq:  Invalid argument(s): Failed to load dynamic library 'zmq.dll': error code 126
[dartzmq] Failed to load library libzmq:  Invalid argument(s): Failed to load dynamic library 'libzmq.dll': error code 126

Based on the docs and what I've seen in other posted issues, I shouldn't need to do anything if I just want to use the default binaries. What am I doing wrong?

How to use Req-Rep mode

I'm a noob in ZeroMQ. The guide says:

The REQ-REP socket pair is in lockstep. The client issues zmq_send() and then zmq_recv(), in a loop (or once if that’s all it needs). Doing any other sequence (e.g., sending two messages in a row) will result in a return code of -1 from the send or recv call. Similarly, the service issues zmq_recv() and then zmq_send() in that order, as often as it needs to.

But there's no such method like zmq_recv, so I tried to use socket.messages.listen() to receive. It DID receive messages, but always throwing exceptions:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ZeroMQException(156384763): Operation cannot be accomplished in current state
#0      _checkErrorCode
package:dartzmq/src/exception.dart:56
#1      _checkReturnCode
package:dartzmq/src/exception.dart:49
#2      ZContext._poll
package:dartzmq/src/zeromq.dart:109
#3      ZContext._startPolling.<anonymous closure>
package:dartzmq/src/zeromq.dart:68
#4      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#5      _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)

I have no idea how to fix this.

The source code is below:

  @override
  void initState() {
    // omitted codes
    enterQueueSocket = ZMQHelper.getNewSocket(Config.replyUrl, SocketType.req);
    // omitted codes
    super.initState();
  }
  void enterQueue() {
    enterQueueSocket.send(utf8.encode(json.encode({
      "enterQueue": true,
      "name": _nameController.text,
      "clientId": "${ZMQHelper.context.hashCode}"
    })));
    enterQueueSocket.messages.listen((event) {
      for (var element in event) {
        print(utf8.decode(element.payload));
      }
    });
  }

I'd appreciate it if anyone would help me.

Failed to load dynamic library issue on MacOS platform

Hello,

I have been trying to use dartzmq on flutter to establish a connection to a remote server host, but I keep getting the error:

[dartzmq] Failed to load library zmq: Invalid argument(s): Failed to load dynamic library 'libzmq.so': dlopen failed: library "libzmq.so" not found
[dartzmq] Failed to load library libzmq: Invalid argument(s): Failed to load dynamic library 'liblibzmq.so': dlopen failed: library "liblibzmq.so" not found
[dartzmq] Failed to load library libzmq-v142-mt-4_3_5: Invalid argument(s): Failed to load dynamic library 'liblibzmq-v142-mt-4_3_5.so': dlopen failed: library "liblibzmq-v142-mt-4_3_5.so" not found

I have built the MacOS platform in my local dartzmq repo and linked it to my flutter app. I was wondering if anyone could help me debug this library issue? If someone has dealt with this problem before, a simple list of steps to fix it would be much appreciated. Thanks!

After two messages, unhandled exemption

When sending messages, the server is sending a reply, however after the second message from the client the following error occurs. I can confirm I receive a response, but this error occurs. This seems to be locking the library in a state where it can no longer send messages nor receive them. Current implementation is equivalent to example code in this repo for listening on a stream and sending using _socket.sendString()

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: ZeroMQException(156384763): Operation cannot be accomplished in current state
#0      _checkErrorCode (package:dartzmq/src/exception.dart:56:5)
#1      _checkReturnCode (package:dartzmq/src/exception.dart:49:5)
#2      ZContext._poll (package:dartzmq/src/zeromq.dart:109:9)
#3      ZContext._startPolling.<anonymous closure> (package:dartzmq/src/zeromq.dart:68:70)
#4      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#5      _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)

ArgumentError (Invalid argument(s): Failed to load dynamic library 'zmq.dll': The specified module could not be found. (error code: 126))

I encountered an error while running the example program. However, I found that the error disappeared after renaming the libzmq-v142-mt-4_3_5.dll file in the build\windows\x64\runner\Debug folder to zmq.dll. I suspect this might be a bug, indicating a possible issue with the copying or building of the zmq dll.

Additionally, I noticed that someone else had experienced a similar issue, which can be referenced here: #22

Link to the example program: https://pub.dev/packages/dartzmq/example

My environment is:

Windows 10
Flutter 3.19.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 7482962148 (7 days ago) • 2024-02-27 16:51:22 -0500
Engine • revision 04817c99c9
Tools • Dart 3.3.0 • DevTools 2.31.1

when running example code to receive message via listen funcion, dartzmq throws exception

I don't know if the reason to this issue happens is the project is now still under development stage. but through observing the source code, I found that maybe one of the reason is the dartzmq doesn't provide the receive function, and the inner strategy is using loop to handle the receive data without sending data for reply. but whether I use reply mode or request mode, zmq doesn't allow no sending action within two receiving actions. so, it seemed the exception occurs. i want to know why the dartzmq has not provide receive funciton directly? or the dartzmq developer has had a solution to solove the problem? I am looking forward to the reply very eagerly. Thanks in advance.

Connect/Send no error message if server is not available

Describe the Bug
I try to use your library with the environment which I described below.
If I call socket.connect and Socket.send if no Server is available there is no error message and no effect... so I can not detect, that something is not okay?

Environment
OS: Archlinux 6.0.12-arch1-1
Android x86 emulator: Pixel 5 API 30
flutter: 3.3.9
compileSdkVersion 33
ndkVersion flutter.ndkVersion

To Reproduce

  // Send a test message
  // => via zmq
  testzmq() {
    // Tst
    final ZContext context = ZContext();
    final ZSocket socket = context.createSocket(SocketType.req);
    socket.connect("tcp://localhost:6555");
    //socket.sendString("Hello");
    socket.send([1, 2]);
    socket.close();
  }

Expected Behavior
Error message if I can not connect to server / Get Stuck on server.connect

Reproducibility
100%

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.