static int Main(string[] args) { if (args.Length != 3) { Console.WriteLine("usage: remote_thr <connect-to> <message-size> <message-count>"); return(1); } string connectTo = args[0]; int messageSize = int.Parse(args[1]); int messageCount = int.Parse(args[2]); var context = ZMQ.CtxNew(); var pushSocket = ZMQ.Socket(context, ZmqSocketType.Push); pushSocket.Connect(connectTo); for (int i = 0; i != messageCount; i++) { var message = new Msg(); message.InitPool(messageSize); pushSocket.Send(ref message, SendReceiveOptions.None); message.Close(); } pushSocket.Close(); context.Terminate(); return(0); }
static int Main(string[] args) { if (args.Length != 3) { Console.WriteLine("usage: local_lat <bind-to> <message-size> <roundtrip-count>"); return(1); } string bindTo = args[0]; int messageSize = int.Parse(args[1]); int roundtripCount = int.Parse(args[2]); var context = ZMQ.CtxNew(); var repSocket = ZMQ.Socket(context, ZmqSocketType.Rep); repSocket.Bind(bindTo); for (int i = 0; i != roundtripCount; i++) { Msg message = repSocket.Recv(SendReceiveOptions.None); if (ZMQ.MsgSize(message) != messageSize) { Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize); return(-1); } repSocket.Send(message, SendReceiveOptions.None); } repSocket.Close(); context.Terminate(); return(0); }
public void ShouldAllowInfinitePolling() { Ctx contextNew = ZMQ.CtxNew(); SocketBase receiver = ZMQ.Socket(contextNew, ZmqSocketType.Dealer); ZMQ.Bind(receiver, "inproc://test"); Task.Factory.StartNew(() => { Thread.Sleep(500); SocketBase sender = ZMQ.Socket(contextNew, ZmqSocketType.Dealer); ZMQ.Connect(sender, "inproc://test"); ZMQ.Send(sender, "ping", SendReceiveOptions.None); ZMQ.Close(sender); }); var pollItems = new PollItem[] { new PollItem(receiver, PollEvents.PollIn) }; Assert.DoesNotThrow(() => ZMQ.Poll(pollItems, -1)); var msg = ZMQ.Recv(receiver, SendReceiveOptions.DontWait); var actual = Encoding.ASCII.GetString(msg.Data, 0, msg.Size); Assert.AreEqual("ping", actual); ZMQ.Close(receiver); ZMQ.Term(contextNew); }
static int Main(string[] args) { if (args.Length != 3) { Console.WriteLine("usage: local_thr <bind-to> <message-size> <message-count>"); return(1); } string bindTo = args[0]; int messageSize = int.Parse(args[1]); int messageCount = int.Parse(args[2]); var context = ZMQ.CtxNew(); var pullSocket = ZMQ.Socket(context, ZmqSocketType.Pull); pullSocket.Bind(bindTo); var message = new Msg(); message.InitEmpty(); pullSocket.Recv(ref message, SendReceiveOptions.None); var stopWatch = Stopwatch.StartNew(); for (int i = 0; i != messageCount - 1; i++) { pullSocket.Recv(ref message, SendReceiveOptions.None); if (message.Size != messageSize) { Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize); return(-1); } } stopWatch.Stop(); var millisecondsElapsed = stopWatch.ElapsedMilliseconds; if (millisecondsElapsed == 0) { millisecondsElapsed = 1; } message.Close(); double messagesPerSecond = (double)messageCount / millisecondsElapsed * 1000; double megabits = messagesPerSecond * messageSize * 8 / 1000000; Console.WriteLine("message size: {0} [B]", messageSize); Console.WriteLine("message count: {0}", messageCount); Console.WriteLine("mean throughput: {0:0.000} [msg/s]", messagesPerSecond); Console.WriteLine("mean throughput: {0:0.000} [Mb/s]", megabits); pullSocket.Close(); context.Terminate(); return(0); }
static int Main(string[] args) { if (args.Length != 3) { Console.WriteLine("usage: remote_lat remote_lat <connect-to> <message-size> <roundtrip-count>"); return(1); } string connectTo = args[0]; int messageSize = int.Parse(args[1]); int roundtripCount = int.Parse(args[2]); var context = ZMQ.CtxNew(); var reqSocket = ZMQ.Socket(context, ZmqSocketType.Req); reqSocket.Connect(connectTo); var message = new Msg(); message.InitPool(messageSize); var stopWatch = Stopwatch.StartNew(); for (int i = 0; i != roundtripCount; i++) { reqSocket.Send(ref message, SendReceiveOptions.None); reqSocket.Recv(ref message, SendReceiveOptions.None); if (message.Size != messageSize) { Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize); return(-1); } } stopWatch.Stop(); message.Close(); double elapsedMicroseconds = stopWatch.ElapsedTicks * 1000000 / Stopwatch.Frequency; double latency = elapsedMicroseconds / (roundtripCount * 2); Console.WriteLine("message size: {0} [B]", messageSize); Console.WriteLine("roundtrip count: {0}", roundtripCount); Console.WriteLine("average latency: {0:0.000} [µs]", latency); reqSocket.Close(); context.Terminate(); return(0); }
/// <summary> /// Create a new context /// </summary> /// <returns>The new context</returns> public static NetMQContext Create() { return(new NetMQContext(ZMQ.CtxNew())); }