Search code examples
flutterdartnetwork-programmingtcpzeromq

Mimic ZeroMQ SUB-Socket (in a PUB/SUB system) with e.g. Socket/WebSocket in Flutter


Community,

I want to use/subscribe a pub-socket on a server that implements ZeroMQ (https://zeromq.org/)

My final product will be a flutter app. It must be running on Android/iOS/Windows/MacOS/Linux/Web. So I'm really careful with the plugin-choice. I do not want to burden myself with an intense amount of platform-specific code, neither do I want to be dependent on plugins that might break under certain conditions on each platform.

I know that there is a ZeroMQ-Plugin, but it has some Unresolved Issues in terms of operability on different platforms. Also I tried to run it on different Windows-machines and it only worked in about 25% of the cases.

Here's the fundamental network-communication between App and Server (see image below).

Is it possible to connect to a ZeroMQ-Publisher-Socket WITHOUT implementing or depending on the C++ compiled file of ZeroMQ? I'm thinking of a Socket or WebSocket, but I'm not even sure if it's technically possible (protocol etc), as I think that ZeroMQ uses it's own protocoll (please verify).

Can I subscribe to a ZeroMQ-Publisher-Socket with Sockets or WebSockets in Flutter? If yes, how? Are there alternatives?

Flutter App trying to connect to a ZeroMQ Serverdartzmq/install

Best regards


Solution

  • Q1 :
    "Is it possible to connect to a ZeroMQ-Publisher-Socket WITHOUT implementing or depending on the C++ compiled file of ZeroMQ?"

    A1 :
    Yes, it is. It is quite enough to re-implement the published ZeroMQ ZMTP RFC-s relevant for the use-case & your code is granted to become interoperable, irrespective of the implementation language / deployment ecosystem, if it meets all the ZMTP RFC-s' mandatory requirements. So it is doable.

    Q2 :
    "... ZeroMQ uses it's own protocoll (please verify)."

    A2 :
    No, in the sense of OSI-ISO-L2/L3 stack.
    Yes, in the sense of higher layer application-driven protocols, where the ZMTP RFC-s apply for the most of the ZeroMQ Scalable Formal Communication Patterns' Archetypes ( may read more on ZeroMQ sockets are not sockets as you know them ), yet there are also tools to interface with O/S plain-sockets' fd-s, where needed. Still A1 applies here.

    Q3 :
    "Can I subscribe to a ZeroMQ-Publisher-Socket with ...? If yes, how?"

    A3 :
    Yes, it possible when your code follows the published ZMTP RFC-s. Implement all ZMTP RFC-s' mandatory properties & you are granted an interoperability with any other, ZeroMQ-ZMTP-RFC-s' compliant, node.

    Q4 :
    "Are there alternatives?"

    A4 :
    Yes, if your design can extend the Server-side, adding another AccessPoint-s there, using ZMQ_STREAM Scalable Formal Communication Archetype there, may reduce your Flutter-side scope of ZMTP RFC-s needed, as interfacing to native plain-socket will be the only one to handle and the "functionality gap" thereof can be handled on the Server-side of the link ( easily handling all the subscription management & message filtering, that must meet the ZeroMQ ZMTP RFC-s, so why not tandem it inside the Server-side before connecting the down-stream to Flutter App - smart, isn't it? )