private static void StartServer(Type interfaceType, Type implType, string pipeName) { //create the server var controller = new RpcController(); var server = new RpcServer(controller); //register the service with the server. We must specify the interface explicitly since we did not use attributes server.GetType() .GetMethod("RegisterService") .MakeGenericMethod(interfaceType) .Invoke(server, new[] { Activator.CreateInstance(implType) }); //build the connection using named pipes try { pipeServerStreamIn = CreateNamedPipe(pipeName + "ctos", PipeDirection.In); pipeServerStreamOut = CreateNamedPipe(pipeName + "stoc", PipeDirection.Out); streamsCreated = true; pipeServerStreamIn.WaitForConnection(); pipeServerStreamOut.WaitForConnection(); //create and start the channel which will receive requests var channel = new StreamRpcChannel(controller, pipeServerStreamIn, pipeServerStreamOut, useSharedMemory: true); channel.Start(); } catch (IOException e) { //swallow and exit Console.WriteLine("Something went wrong (pipes busy?), quitting: " + e); throw; } }
public void Send() { var channel = new StreamRpcChannel(controller.Object, readStream, writeStream); channel.Start(); channel.Send(testMessage); channel.CloseAndJoin(false); writeStream.Seek(0, SeekOrigin.Begin); var receivedMessage = Serializer.DeserializeWithLengthPrefix<RpcMessage>(writeStream, PrefixStyle.Fixed32); Assert.That(receivedMessage.IsEquivalentTo(testMessage), Is.True); }
public void Send() { var channel = new StreamRpcChannel(controller.Object, readStream, writeStream); channel.Start(); channel.Send(testMessage); channel.CloseAndJoin(false); writeStream.Seek(0, SeekOrigin.Begin); var receivedMessage = Serializer.DeserializeWithLengthPrefix <RpcMessage>(writeStream, PrefixStyle.Fixed32); Assert.That(receivedMessage.IsEquivalentTo(testMessage), Is.True); }
public void Receive() { Serializer.SerializeWithLengthPrefix(readStream, testMessage, PrefixStyle.Fixed32); readStream.Seek(0, SeekOrigin.Begin); ManualResetEvent doneEvent = new ManualResetEvent(false); controller.Setup(c => c.Receive(It.Is<RpcMessage>(m => m.IsEquivalentTo(testMessage)))) .Callback(() => doneEvent.Set()); var channel = new StreamRpcChannel(controller.Object, readStream, writeStream); channel.Start(); doneEvent.WaitOne(2000); channel.CloseAndJoin(); controller.VerifyAll(); }
public void Receive() { Serializer.SerializeWithLengthPrefix(readStream, testMessage, PrefixStyle.Fixed32); readStream.Seek(0, SeekOrigin.Begin); ManualResetEvent doneEvent = new ManualResetEvent(false); controller.Setup(c => c.Receive(It.Is <RpcMessage>(m => m.IsEquivalentTo(testMessage)))) .Callback(() => doneEvent.Set()); var channel = new StreamRpcChannel(controller.Object, readStream, writeStream); channel.Start(); doneEvent.WaitOne(2000); channel.CloseAndJoin(); controller.VerifyAll(); }
private static StreamRpcChannel SetupConnection(RpcController controller, string pipeName) { // create stream (IPC only) var pipeClientStreamIn = new NamedPipeClientStream(".", pipeName + "stoc", PipeDirection.In); var pipeClientStreamOut = new NamedPipeClientStream(".", pipeName + "ctos", PipeDirection.Out); try { pipeClientStreamIn.Connect(15000); //15secs to connect, otherwise fail pipeClientStreamOut.Connect(1000); } catch (TimeoutException) { throw new InvalidOperationException( "Unable to connect to remote instance: instance crashed during initialization, or existing instance still running?"); } //create and start the channel which will receive requests var channel = new StreamRpcChannel(controller, pipeClientStreamIn, pipeClientStreamOut, useSharedMemory: true); channel.Start(); return(channel); }