private static void EchoServer(string[] args) { Console.WriteLine(@"EchoServer start"); // {pipeName} {maxNumberOfServerInstances} {initialNumberOfServerInstances} var name = args.Length > 0 ? args[0] : "EchoServer"; var max = args.Length > 1 ? int.Parse(args[1]) : 1; var num = args.Length > 2 ? int.Parse(args[2]) : 1; Console.Title = $"EchoServer [{name}]"; var server = new NamedPipeServer(name, max, num, (s, e) => { switch (e.Request) { case "Ping": e.Response = "Pong"; break; case "Exit": e.Response = "OK"; ((NamedPipeServerInstance)s).Dispose(); break; default: e.Response = "ERROR unknown command"; break; } }); _consoleCtrlHandler += sig => { if (sig == CtrlType.CTRL_CLOSE_EVENT) { server.Dispose(); } return(false); }; SetConsoleCtrlHandler(_consoleCtrlHandler, true); server.Run(); Console.WriteLine(@"EchoServer exit"); }
public void StartServerAndClientAndSend() { var pipeName = Guid.NewGuid().ToString("N"); var server = new NamedPipeServer(pipeName, 1, 1, (s, e) => e.Response = "Pong"); var client = new NamedPipeClient(pipeName, 100); var response = client.SendRequest("Ping"); Assert.AreEqual("Pong", response); client.Dispose(); server.Dispose(); }
public void StartServerAndClientAndDispose() { var pipeName = Guid.NewGuid().ToString("N"); var server = new NamedPipeServer(pipeName, 1, 1, (s, e) => {}); server.Start(); var client = new NamedPipeClient(pipeName, 100); client.Dispose(); server.Dispose(); }
static void Server() { var server = new NamedPipeServer(pipeName, 4, 1); server.RequestReceived += (s, e) => e.Response = "Echo. " + e.Request; server.Start(); Console.WriteLine("Server started"); Task.Delay(10000).Wait(); Console.WriteLine("Server shutdown"); server.Dispose(); }
protected override void OnStart(string[] args) { work = true; server?.Dispose(); cts = new CancellationTokenSource(); ct = cts.Token; NewServer(); if (!BW_NPipe.IsBusy) { BW_NPipe.RunWorkerAsync(); } }
static void Server() { var server = new NamedPipeServer(pipeName); server.newRequestEvent += (s, e) => { e.Response = "Echo. " + e.Request; Console.WriteLine(e.Request); }; server.newServerInstanceEvent += (s, e) => Console.WriteLine("server start"); server.Start(); Task.Delay(10000).Wait(); server.Dispose(); }
protected override void OnStartup(StartupEventArgs e) { Log.Info("Launching Windows desktop integration"); base.OnStartup(e); Log.Debug("Setting up event handler to check for parent process"); ProcessExitListenerManager.ProcessExited += ProcessExitListenerManagerOnProcessExited; #if !DEBUG _runOnceMutex = new Mutex(true, Globals.InteropMutexName, out var mutexNew); if (!mutexNew) { Shutdown(); } #endif VerifySimpleAudioManager(); if (!TryLaunchInteropChannel()) { Log.Fatal("Failed to launch named pipe for IPC with web application"); _namedPipeServer?.Dispose(); } }
public void StartServerWithMaxConnections() { var pipeName = Guid.NewGuid().ToString("N"); NamedPipeServer server = null; try { server = new NamedPipeServer(pipeName, -1, 1, (sender, messageArgs) => { Debug.WriteLine(messageArgs.Request); messageArgs.Response = "Echo"; }); } catch (Exception ex) { Debug.WriteLine(ex); } finally { server?.Dispose(); } }
public void StartServerAndDisposeTest() { var pipeName = Guid.NewGuid().ToString("N"); NamedPipeServer server = null; try { server = new NamedPipeServer(pipeName, 1, 1); Thread.Sleep(500); server.Dispose(); Thread.Sleep(500); Debugger.Break(); } catch (Exception ex) { Debug.WriteLine(ex); } finally { server?.Dispose(); } }
protected override void OnExit(ExitEventArgs args) { base.OnExit(args); pipeServer.Dispose(); }