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

PUB SUB CURVE #412

Closed
Deeptradingfx opened this issue Aug 10, 2020 · 2 comments · Fixed by #682
Closed

PUB SUB CURVE #412

Deeptradingfx opened this issue Aug 10, 2020 · 2 comments · Fixed by #682

Comments

@Deeptradingfx
Copy link

well im trying for weeks to enable a simple curve on pub and sub! i found example for v6 in type script but when i try to subscribe specific topic doesn't work!

could someone please give me an example in the code below using curve

`const zmq = require("zeromq")

async function run() {
const sock = new zmq.Subscriber

sock.connect("tcp://127.0.0.1:3000")
sock.subscribe("kitty cats")
console.log("Subscriber connected to port 3000")

for await (const [topic, msg] of sock) {
console.log("received a message related to:", topic, "containing message:", msg)
}
}

run()`

`const zmq = require("zeromq")

async function run() {
const sock = new zmq.Publisher

await sock.bind("tcp://127.0.0.1:3000")
console.log("Publisher bound to port 3000")

while (true) {
console.log("sending a multipart message envelope")
await sock.send(["kitty cats", "meow!"])
await new Promise(resolve => setTimeout(resolve, 500))
}
}

run()`

@Deeptradingfx
Copy link
Author

found a solution is working if someone has a better solution share it thank you

` const zmq = require("zeromq")

  const sock = new zmq.Subscriber
  const serverPublickey = "am%ch(6JxceNGl+)s0G3Q=-kqC.9@s-b3H!4ldkr" 
  const Keypair = zmq.curveKeyPair()
  
    // Setup encryption.

for (const s of [sock]) {
s.curveServerKey = serverPublickey;
s.curvePublicKey = Keypair.publicKey;
s.curveSecretKey = Keypair.secretKey;
}
async function run() {
sock.connect("tcp://127.0.0.1:3000")
sock.subscribe("kitty cats")
console.log("Subscriber connected to port 3000")

for await (const [topic, msg] of sock) {
console.log("received a message related to:", topic, "containing message:", msg)
}
}

run()

// pub

const zmq = require("zeromq")
const sock = new zmq.Publisher

  const publicKey = "am%ch(6JxceNGl+)s0G3Q=-kqC.9@s-b3H!4ldkr" 
  const Keypair = zmq.curveKeyPair()
  
    // Setup encryption.

for (const s of [sock]) {
s.curveServer = true;
s.curvePublicKey = publicKey;
s.curveSecretKey = Keypair.secretKey;
}

async function run() {

await sock.bind("tcp://127.0.0.1:3000")
console.log("Publisher bound to port 3000")

while (true) {
console.log("sending a multipart message envelope")
await sock.send(["kitty cats", "meow!"])
await new Promise(resolve => setTimeout(resolve, 500))
}
}

run()`

@aminya
Copy link
Member

aminya commented Dec 29, 2024

Fixed in #682

@aminya aminya closed this as completed Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants