I'm working on a program in C++ that needs to be able to send / receive JSON
-payloads from an arbitrary number of other clients.
At first, I tried to implement PubNub service, but I figured I can't get and publish messages at the same time (even using two different contexts on distinct threads). I need to be able to do that. I also found that PubNub has too much latency for my liking.
I came across the ZeroMQ library which has a PUB/SUB
model that would suit my needs. But all examples I came across explain how to implement it in a way that one process is a Publisher OR a Subscriber, and not both at the same time.
Ideally, I would like to program a server that would relay all messages coming from anyone, to anyone subscribed to a specific channel specified in the message. Anyone should be able to receive and publish messages to anyone else on the network, provided they are subscribed to the correct channel.
UPDATE 1:
Note : I do not need insurance of receipt because payload N+1 will take precedence over payload N. I want a send and forget mean of communication (UDP-like).
As requested : The PubNub limit of 32 kB
per JSON
-payload was perfect for me, I do not need more. In fact, my payloads are around 4 kB
in average. All instances of clients will run on the same local network, so latency should be less than 5 ms
ideally. As for the number of clients, there won't be more than 4 clients subscribed to the same channel/topic at a time.
UPDATE 2 :
I cannot predict how many channels/topics will exist ahead of time, but it will be in the order of dozens (most of the time), hundreds (at peak). Not thousands.
Questions:
Q1:
- Can I implement such a behavior using ZeroMQ
?
Q2:
- Is there any working sample demonstrating that (preferably in C++
) ?
Q3:
- If not, any suggestions for a library in C++
?