Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate receive messages arriving? #200

Open
DrYSG opened this issue Oct 9, 2018 · 1 comment
Open

duplicate receive messages arriving? #200

DrYSG opened this issue Oct 9, 2018 · 1 comment

Comments

@DrYSG
Copy link

DrYSG commented Oct 9, 2018

This is very odd. I have a C++ program using nng Nanomsg (wire protocol is identical to nanomsg).
https://github.com/nanomsg/nng

I have a simple test harness (client.exe and server.exe) using the CPP interface and I only see one copy of a message (sent in over bus protocol). However with this JS package I am getting two copies of each message sent (cpp -> JS node program).

Node Version: 10.9.0
nanomsg: 4.0.2

This means that I get two calls to the receive() callback for each packet that arrives.

Here is my nanomsg receiver


const nano = require('nanomsg')
const { Topics } = require('./Payloads/Packet')

class LMB {
    constructor(config) {
        this.sock
        this.config = config
        this.nodeName = config.nodeName
        this.topicList = config.topicList
        this.topics = Topics
    }

    connect() {
        this.sock = nano.socket('bus')
        this.sock.bind(this.config.urlList[0])
        this.sock.connect(this.config.urlList[1])
        this.sock.on('data', this.receive.bind(this))
    }

    send(topic, payload) {
        let size = payload.length
        let packet = new ArrayBuffer(size + 8)
        let buffer = new Uint8Array(packet)
        let view = new DataView(packet)
        view.setUint32(0, topic, true)
        view.setUint32(4, size, true)
        buffer.set(payload, 8)
        this.sock.send(buffer)
    }

    receive(packet) {
        let view = new DataView(packet.buffer)
        let topic = view.getUint32(0, true)
        let size = view.getUint32(4, true)
        let payload = packet.slice(8, packet.length - 1)
        global.Dispatcher.process(topic, size, payload)
    }
}

module.exports = { LMB }

and here is the config that it uses, and the two copies of the start message that appear. I confirmed with the VSCODE debugger via breakpoints and the receive() method is being called twice for each arrival of a packet over the network.

C:\Program Files\nodejs\node.exe --inspect-brk=48723 orch.js 
Debugger listening on ws://127.0.0.1:48723/a3bc5322-9c99-4c22-b1fb-f053bb8d144f

For help, see: https://nodejs.org/en/docs/inspector

Orcestrator config: 
{
    "nodeName": "YSG4206-Orchestrator",
    "urlList": [
        "tcp://127.0.0.1:2019",
        "tcp://127.0.0.1:2018"
    ],
    "topicList": [
        "sim.Actor.State.Test"
    ]
}
Waiting for messages..
{
    "topic": 6,
    "size": 144,
    "topicString": "scenario.Ready",
    "source": "AFSIM-YSG-Server",
    "systemTime": {
        "low": -433850073,
        "high": 30695395
    },
    "systemTimeString": "Tue Oct  9 11:22:32 2018",
    "description": "AFSIM Ready"
}
******* starting ******
{
    "topic": 6,
    "size": 144,
    "topicString": "scenario.Ready",
    "source": "AFSIM-YSG-Server",
    "systemTime": {
        "low": -433850073,
        "high": 30695395
    },
    "systemTimeString": "Tue Oct  9 11:22:32 2018",
    "description": "AFSIM Ready"
}
******* starting ******

@DrYSG
Copy link
Author

DrYSG commented Oct 9, 2018

It was suggested that I should not be doing both a bind(local) and connect(remote) and that that might be causing two connections to be made. But I am finding that I need both for there to be traffic,.

currently:

local = tcp://127.0.0.1:2019
remote = tcp://127.0.0.1:2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants