private static async Task Main() { var ws = new WsServer(); _ = Task.Run(Work(ws)).ConfigureAwait(false); await ws.Listen(IPAddress.Parse("127.0.0.1"), LISTEN_PORT).ConfigureAwait(false); }
private static Func <Task> Work(WsServer ws) { var(path, args) = GetToolInfo(); var psi = new ProcessStartInfo(path, args); psi.UseShellExecute = false; psi.RedirectStandardError = false; psi.RedirectStandardOutput = true; psi.RedirectStandardInput = false; psi.CreateNoWindow = false; var p = Process.Start(psi); var reader = p.StandardOutput; return(async() => { while (true) { if (reader.EndOfStream) { await Task.Delay(100).ConfigureAwait(false); continue; } string line = await reader.ReadLineAsync().ConfigureAwait(false); ws.SendMessage(line); await Task.Delay(50).ConfigureAwait(false); } }); }
public ChatSession(WsServer server) : base(server) { }