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(); } } }); }
public ReplyData GetReply(InputData data) { var inputBuf = ByteArray.CreateFrom(data); EtwSource.Instance.SendInputData(inputBuf); replyReceived.WaitOne(); return(replyData); }
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"); }
public ReplyData GetReply(InputData data) { var inputBuf = ByteArray.CreateFrom(data); request.SendFrame(inputBuf); var replyData = request.ReceiveFrameBytes(); return(replyData.ConvertTo <ReplyData>()); }
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)) }); }
public ReplyData GetReply(InputData data) { byte[] inputBuffer = ByteArray.CreateFrom(data); server.SendAsync(inputBuffer, inputBuffer.Length, destination).Wait(); var message = replySocket.ReceiveAsync().Result.Buffer; var replyData = message.ConvertTo <ReplyData>(); return(replyData); }
public ReplyData GetReply(InputData data) { byte[] inputBuffer = ByteArray.CreateFrom(data); server.Send(inputBuffer, inputBuffer.Length); var peerAddress = new IPEndPoint(IPAddress.Any, 0); var message = replySocket.Receive(ref peerAddress); var replyData = message.ConvertTo <ReplyData>(); return(replyData); }
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); } }
public ReplyData GetReply(InputData data) { var inputBuf = ByteArray.CreateFrom(data); request.Send(new ZFrame(inputBuf)); using (ZFrame reply = request.ReceiveFrame()) { var replyData = reply.Read(); return(replyData.ConvertTo <ReplyData>()); } }
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); } }); }
public ReplyData GetReply(InputData data) { var inputBuf = ByteArray.CreateFrom(data); view.Write(0, inputBuf.Length); view.WriteArray(4, inputBuf, 0, inputBuf.Length); requestReadyEvent.Set(); replyReadyEvent.WaitOne(); int replyLength = view.ReadInt32(0); var buf = new byte[replyLength]; view.ReadArray(4, buf, 0, buf.Length); var replyData = buf.ConvertTo <ReplyData>(); return(replyData); }
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); } }; }
public ReplyData GetReply(InputData data) { reply = null; var corrId = Guid.NewGuid().ToString(); var props = channel.CreateBasicProperties(); props.ReplyTo = replyQueueName; props.CorrelationId = corrId; var messageBytes = ByteArray.CreateFrom(data); channel.BasicPublish(exchange: "", routingKey: "rpc_queue", basicProperties: props, body: messageBytes); replyReady.WaitOne(); return(reply); }
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)); } } }); }
public ReplyData GetReply(InputData data) { Task.Factory.StartNew(() => { messageHandler = new MessageHandler(this); Application.Run(); }); var inputBuf = ByteArray.CreateFrom(data); WindowSender.SendMessage(typeof(IContract).Name + "_request", inputBuf); Console.WriteLine("Request sent"); replyReadyEvent.WaitOne(); WindowSender.SendQuitMessage(messageHandler.Handle); var replyData = replyBuf.ConvertTo <ReplyData>(); return(replyData); }
public static void Send <T>(this Stream stream, T data) { SendByteArray(stream, ByteArray.CreateFrom(data)); }
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(); }