Created
September 10, 2012 15:49
-
-
Save janderit/3691683 to your computer and use it in GitHub Desktop.
Example zeromq usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class ZmqEventServer | |
{ | |
public ZmqEventServer(ZmqPollPool pool, NetworkAddress broadcastAddress, NetworkAddress listenAddress) | |
{ | |
if (!listenAddress.IsBindable) throw new ArgumentException("listen address must be bindable (i.e. IP address instead of DNS name)"); | |
ZmqSocket broadcast=null; | |
var broadcastAddr = broadcastAddress.String; | |
var listenAddr = listenAddress.String; | |
pool.MarshalAndWait((context, register) => | |
{ | |
broadcast = context.CreateSocket(SocketType.PUB); | |
broadcast.Bind(broadcastAddr); | |
register(broadcast); | |
}); | |
pool.MarshalAndWait((context, register) => | |
{ | |
var listen = context.CreateSocket(SocketType.PULL); | |
listen.Bind(listenAddr); | |
register(listen, datagram => Helper.Send(broadcast, datagram.ToList())); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment