Exemplo n.º 1
0
        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();
        }
    }