No-nonsense, high performance pub-sub for distributing time-critical data over UDP.
Create a server and publish a stream of realtime data:
var server = new ZetaUdpPublisher();
server.Start(1000); // Listed on UDP port 1000
server.Publish(new StringMessage("Message 1")); // Publish a stream of messages
server.Publish(new StringMessage("Message 2"));
server.Publish(new StringMessage("Message 3"));
// etc...
Create clients and subscribe to the data stream:
var client = new ZetaUdpSubscriber();
client.Start("127.0.0.1:1000"); // Connect to localhost port 1000
while (true) {
var msg = client.Read<StringMessage>(); // Receive message
Console.WriteLine($"> {msg}");
}
If values are published faster than clients can recieve them, the older "stale" updates will be dropped in favour of the more recent updates.
If you have multiple seperate streams of data, you can seperate them by assigning a numeric "topic" to each stream:
server.Publish(new StringMessage("Topic 1, message 1"), 1);
server.Publish(new StringMessage("Topic 2, message 1"), 2);
This means that if receivers incur any form of delay receiving updates, they will always receive the latest update for each topic.
The server will automatically retransmit the latest value for each topic.
You can stop this from occuring by publishing a NULL on a topic:
server.Publish(null, 1);
Of course! StringMessage is the simplest type of message for transporting strings. You can use BinaryMessage for byte arrays or create your own for even better control. See InvertedTomato.Messages for all types. Feel free to request (or pull-request) new ones - they're super easy to make.
You'll never receive an older update after a newer one. It is possible that an update may be lost though in favour of a newer one, as discussed above.
Yes, Zeta will retransmit updates as needed.
It depends on your network. Most networks support UDP packets of 1,500 bytes or greater. However old-school networks might only support 520 bytes. By default Zeta is configured to use this worst-case value of 520 bytes. Change this in Mtu
if needed.
If a message exceeds the maximum of the network (and you've incorrectly increased the maximum in Mtu
) the messages will never arrive at clients.
Zeta is thread safe. You can call Publish
from as many threads as you want, simaltaniously.