Created
December 10, 2011 17:30
-
-
Save rasmuskl/1455681 to your computer and use it in GitHub Desktop.
ZeroMQ test
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
using System; | |
using System.Diagnostics; | |
using ZeroMQ.Sockets; | |
namespace Client | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
const int numberOfMessages = 100000; | |
var stopwatch = Stopwatch.StartNew(); | |
using (var context = ZmqContext.Create()) | |
{ | |
using (var socket = context.CreateRequestSocket()) | |
{ | |
socket.Connect("tcp://127.0.0.1:9001"); | |
for (var i = 0; i < numberOfMessages; i++) | |
{ | |
socket.Send("PING".ZmqEncode()); | |
socket.Receive(); | |
} | |
} | |
} | |
stopwatch.Stop(); | |
var elapsedMs = stopwatch.ElapsedMilliseconds; | |
var messagesPerSec = numberOfMessages * 1000 / elapsedMs; | |
Console.Out.WriteLine("Elapsed: {0} ms for {1} messages. ({2} / sec)", elapsedMs, numberOfMessages, messagesPerSec); | |
Console.ReadLine(); | |
} | |
} | |
} |
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
using System; | |
using ZeroMQ.Sockets; | |
namespace Server | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var response = "PONG".ZmqEncode(); | |
using (var context = ZmqContext.Create()) | |
{ | |
using (var socket = context.CreateReplySocket()) | |
{ | |
socket.Bind("tcp://*:9001"); | |
while (true) | |
{ | |
socket.Receive(); | |
socket.Send(response); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment