static async Task Run() { Console.WriteLine("Starting ZMQ Server"); var server = new ResponseSocket(); var serverCert = CertificatesManager.GetServerCertificate(); server.Options.CurveServer = true; server.Options.CurveCertificate = serverCert; server.Bind(@"tcp://localhost:5556"); (byte[], bool)socketMsgRequest; while (true) { socketMsgRequest = await server.ReceiveFrameBytesAsync().ConfigureAwait(false); if (!socketMsgRequest.Item2) { break; } } var receivedMsg = Message.Parser.ParseFrom(socketMsgRequest.Item1); Console.WriteLine("From Client: {0} - {1}", receivedMsg.Id, receivedMsg.Data); server.SendFrame( (new Message() { Id = 2, Data = "Response from server", }) .ToByteArray()); }
static async Task Run(string[] args) { Console.WriteLine("Starting ZMQ Client"); if (args == null || args.Length < 1) { Console.WriteLine(); Console.WriteLine("Usage: ./{0}", AppDomain.CurrentDomain.FriendlyName); Console.WriteLine(); args = new[] { "Hello" }; } var arg = args[0]; Message msg = new() { Data = arg, Id = 1 }; var clientCertificatePair = new NetMQCertificate(); var client = new RequestSocket(); //client.Options.CurveServerCertificate = CertificatesManager.GetServerCertificate(); client.Options.CurveServerKey = CertificatesManager.GetServerCertificate().PublicKey; client.Options.CurveCertificate = clientCertificatePair; client.Connect(@"tcp://localhost:5556"); var bufferedMsg = msg.ToByteArray(); client.SendFrame(bufferedMsg); (byte[], bool)socketMsgResponse; while (true) { socketMsgResponse = await client.ReceiveFrameBytesAsync().ConfigureAwait(false); if (!socketMsgResponse.Item2) { break; } } var receivedMsg = Message.Parser.ParseFrom(socketMsgResponse.Item1); Console.WriteLine("From Server: {0} - {1}", receivedMsg.Id, receivedMsg.Data); Console.WriteLine(); Console.Write("Press any key to exit..."); Console.ReadKey(); } }