Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
                }
            });
        }
Esempio n. 3
0
 public ChatSession(WsServer server) : base(server)
 {
 }