예제 #1
0
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                EventWaitHandle requestReadyEvent = OpenEvent(RequestReadyEventName);
                EventWaitHandle replyReadyEvent   = OpenEvent(ReplyReadyEventName);

                using (requestReadyEvent)
                    using (replyReadyEvent)
                        using (var file = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen(SharedFileName, Constants.MaxMessageSize))
                            using (var view = file.CreateViewAccessor())
                            {
                                while (WaitHandle.WaitAny(new WaitHandle[] { stopEvent, requestReadyEvent }) == 1)
                                {
                                    int inputLength = view.ReadInt32(0);
                                    var data        = new byte[inputLength];
                                    view.ReadArray(4, data, 0, data.Length);
                                    var inputData = data.ConvertTo <InputData>();
                                    var replyData = ServerLogic.Convert(inputData);
                                    var replyBuf  = ByteArray.CreateFrom(replyData);
                                    view.Write(0, replyBuf.Length);
                                    view.WriteArray(4, replyBuf, 0, replyBuf.Length);
                                    replyReadyEvent.Set();
                                }
                            }
            });
        }
예제 #2
0
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    server.WaitForConnection();

                    while (true)
                    {
                        var inputData = server.Receive <InputData>();
                        if (inputData == null)
                        {
                            break;
                        }
                        var reply = ServerLogic.Convert(inputData);
                        server.Send(reply);

                        server.WaitForPipeDrain();
                    }

                    server.Disconnect();
                }
            });
        }
예제 #3
0
        private static void Main(string[] args)
        {
            inputData = new InputData
            {
                Content = new byte[1]
            };
            new Random().NextBytes(inputData.Content);
            expectedReply = ServerLogic.Convert(inputData);

            string ipcMethod;

            if (args.Length > 0)
            {
                ipcMethod = args[0];
            }
            else
            {
                Console.Write("Please specify IPC client method to use: ");
                ipcMethod = Console.ReadLine();
            }
            switch (ipcMethod)
            {
            case "wcf":
                Test <WcfClient>();
                break;

            case "wcftcp":
                Test <WcfTcpClient>();
                break;

            case "udp":
                Test <UdpClient>();
                break;

            case "tcp":
                Test <TcpClient>();
                break;

            case "pipe":
                Test <NamedPipeClient>();
                break;

            case "mmf":
                Test <MmfClient>();
                break;

            case "zeromq":
                Test <ZeroMqClient>();
                break;

            case "rabbitmq":
                Test <RabbitMqClient>();
                break;
            }
            Console.WriteLine("Client test completed.");
            Console.ReadLine();
        }
예제 #4
0
        private void ProcessData(byte[] inputBuf)
        {
            var inputData = inputBuf.ConvertTo <InputData>();
            var reply     = ServerLogic.Convert(inputData);
            var replyBuf  = ByteArray.CreateFrom(reply);

            WindowSender.SendMessage(typeof(IContract).Name + "_reply", replyBuf);
            Console.WriteLine("Reply sent");
        }
예제 #5
0
        public HttpResponseMessage Post()
        {
            var body  = Request.Content.ReadAsByteArrayAsync().Result;
            var reply = ServerLogic.Convert(body.ConvertTo <InputData>());

            return(new HttpResponseMessage()
            {
                Content = new ByteArrayContent(ByteArray.CreateFrom(reply))
            });
        }
예제 #6
0
 private void HandleEtwEvent(TraceEvent eventData)
 {
     if ((int)eventData.ID == EtwSource.RequestEventId)
     {
         var data      = eventData.PayloadByName("data") as byte[];
         var inputData = data.ConvertTo <InputData>();
         var reply     = ServerLogic.Convert(inputData);
         var replyBuf  = ByteArray.CreateFrom(reply);
         EtwSource.Instance.SendReplyData(replyBuf);
     }
 }
예제 #7
0
 public void Start()
 {
     Task.Factory.StartNew(() =>
     {
         var peerAddress = new IPEndPoint(IPAddress.Any, 0);
         replySocket.Connect(Program.ClientIP, 16001);
         while (true)
         {
             var message     = server.Receive(ref peerAddress);
             var inputData   = message.ConvertTo <InputData>();
             var reply       = ServerLogic.Convert(inputData);
             var replyBuffer = ByteArray.CreateFrom(reply);
             replySocket.Send(replyBuffer, replyBuffer.Length);
         }
     });
 }
예제 #8
0
        public void Start()
        {
            factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };
            connection = factory.CreateConnection();
            channel    = connection.CreateModel();

            channel.QueueDeclare(queue: "rpc_queue", durable: false,
                                 exclusive: false, autoDelete: false, arguments: null);
            channel.BasicQos(0, 1, false);
            var consumer = new EventingBasicConsumer(channel);

            channel.BasicConsume(queue: "rpc_queue",
                                 noAck: false, consumer: consumer);

            consumer.Received += (model, ea) =>
            {
                byte[] response = null;

                var body       = ea.Body;
                var props      = ea.BasicProperties;
                var replyProps = channel.CreateBasicProperties();
                replyProps.CorrelationId = props.CorrelationId;

                try
                {
                    var inputData = body.ConvertTo <InputData>();
                    var replyData = ServerLogic.Convert(inputData);
                    response = ByteArray.CreateFrom(replyData);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: {0}", e);
                    response = new byte[0];
                }
                finally
                {
                    channel.BasicPublish(exchange: "", routingKey: props.ReplyTo,
                                         basicProperties: replyProps, body: response);
                    channel.BasicAck(deliveryTag: ea.DeliveryTag,
                                     multiple: false);
                }
            };
        }
예제 #9
0
 public void Start()
 {
     context   = new ZContext();
     responder = new ZSocket(context, ZSocketType.REP);
     responder.Bind("tcp://*:18000");
     Task.Factory.StartNew(() =>
     {
         while (true)
         {
             // Receive
             using (ZFrame request = responder.ReceiveFrame())
             {
                 byte[] inputBuf = request.Read();
                 var inputData   = inputBuf.ConvertTo <InputData>();
                 var replyData   = ServerLogic.Convert(inputData);
                 byte[] replyBuf = ByteArray.CreateFrom(replyData);
                 responder.Send(new ZFrame(replyBuf));
             }
         }
     });
 }
예제 #10
0
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                var requestQueueName = string.Format(".\\Private$\\{0}_requests", typeof(IContract).Name);
                var replyQueueName   = string.Format("FormatName:Direct=TCP:{0}\\Private$\\{1}_replies", Program.ClientIP, typeof(IContract).Name);

                requestQueue = CreateQueue(requestQueueName);
                replyQueue   = CreateQueue(replyQueueName);

                requestQueue.Formatter = new BinaryMessageFormatter();
                replyQueue.Formatter   = new BinaryMessageFormatter();

                while (true)
                {
                    var msg   = requestQueue.Receive();
                    var data  = (InputData)msg.Body;
                    var reply = ServerLogic.Convert(data);
                    replyQueue.Send(reply);
                }
            });
        }
예제 #11
0
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                listener.Start();

                while (true)
                {
                    var tcpClient = listener.AcceptTcpClient();
                    Console.WriteLine("Connected");
                    tcpClient.NoDelay = true;
                    var networkStream = tcpClient.GetStream();
                    try
                    {
                        while (true)
                        {
                            var inputData = networkStream.Receive <InputData>();
                            if (inputData == null)
                            {
                                Console.WriteLine("Disconnected");
                                break;
                            }
                            var reply = ServerLogic.Convert(inputData);
                            networkStream.Send(reply);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Exception: {0}", e);
                    }
                    finally
                    {
                        tcpClient.Dispose();
                    }
                }
            });
        }
예제 #12
0
 public ReplyData GetReply(InputData data)
 {
     return(ServerLogic.Convert(data));
 }
예제 #13
0
        private static void Main(string[] args)
        {
            inputData = new InputData
            {
                Content = new byte[100 * 1024]
            };
            new Random().NextBytes(inputData.Content);
            expectedReply = ServerLogic.Convert(inputData);

            string ipcMethod;

            if (args.Length > 0)
            {
                ipcMethod = args[0];
            }
            else
            {
                Console.Write("Please specify IPC client method to use: ");
                ipcMethod = Console.ReadLine();
            }
            switch (ipcMethod)
            {
            case "noipc":
                var inputBuf = ByteArray.CreateFrom(inputData);
                var input    = inputBuf.ConvertTo <InputData>();
                var reply    = ServerLogic.Convert(input);
                var replyBuf = ByteArray.CreateFrom(reply);
                VerifyReply(replyBuf.ConvertTo <ReplyData>());
                break;

            case "wcf":
                Test <WcfClient>();
                break;

            case "wcftcp":
                Test <WcfTcpClient>();
                break;

            case "udp":
                Test <UdpClient>();
                break;

            case "tcp":
                Test <TcpClient>();
                break;

            case "remoting":
                Test <RemotingClient>();
                break;

            case "mq":
                Test <MessageQueueClient>();
                break;

            case "pipe":
                Test <NamedPipeClient>();
                break;

            case "mmf":
                Test <MmfClient>();
                break;

            case "etw":
                Test <EtwClient>();
                break;

            case "wmcopydata":
                Test <WmCopyDataClient>();
                break;

            case "zeromq":
                Test <ZeroMqClient>();
                break;

            case "rabbitmq":
                Test <RabbitMqClient>();
                break;

            case "webapi":
                Test <WebApiClient>();
                break;
            }
            Console.WriteLine("Client test completed.");
            Console.ReadLine();
        }