zeromq / zeromq.js

:zap: Node.js bindings to the ØMQ library
http://zeromq.github.io/zeromq.js/
MIT License
1.47k stars 211 forks source link

Can't receive messages from python zmq in node zeromq using electron #413

Open Wintersunner opened 4 years ago

Wintersunner commented 4 years ago

Describe the bug I'm sending a message from Python script, and receiving it in my electron app... It's very buggy most of the time. Sometimes I only receive the first message, sometimes I don't receive any message at all... I'm receiving the message from another python script but the node one doesn't really do as expected I don't know it it is relevant or not after I close the socket I receive all the unreceived messages at once.

Reproducing Install Vue Electron from https://github.com/SimulatedGREG/electron-vue Install zeromq (doesn't matter tried both 5.* and 6.0.0-beta.6)

Expected behavior A clear and concise description of what you expected to happen.

Tested on

This is the nodejs/electron code

<template>
    <div>
        <button @click="disconnect">disconnect</button>
        <button @click="connect">Connect</button>
    </div>
</template>

<script>
    const zmq = require('zeromq');

    export default {
        name: "Socket.vue",
        data() {
            return {
                socket: new zmq.Pull()
            }
        },
        mounted() {
            console.log("Socket Mounted!")
        },
        methods: {
            connect() {
                this.initSocket();
            },
            disconnect() {
                this.socket.disconnect("tcp://localhost:6969")
                console.log("Disconnected")
            },
            async initSocket() {
                // await this.socket.bind("tcp://*:6969")
                await this.socket.connect("tcp://localhost:6969")
                console.log("Connected to Port 6969")

                for await (const [msg] of this.socket) {
                    console.log("work: %s", msg.toString())
                }
            }
        }
    }
</script>

and this is the python script

import time
import zmq

context = zmq.Context()
socket = context.socket(zmq.PUSH)
socket.bind("tcp://*:6969")
print("Connected And Ready...")

while True:
    #  Wait for next request from client
    message = socket.send_json({'message': 'message'})
    # print("Received request: %s" % message)

    #  Do some 'work'
    time.sleep(2)

    #  Send reply back to client
    # socket.send(b"World")
niemes commented 3 years ago

Same problem... Using Nodejs Client Zero response from zmq python server.