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 ******
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
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.