public async Task DoClientAsync() { try { using (var stream = _client.GetStream()) { using (var sr = new StreamReader(stream)) using (var sw = new StreamWriter(stream)) { await sw.WriteLineAsync("Connection accepted!").ConfigureAwait(false); RWControl.writeTofile(DateTime.Now + " - " + "[" + _clientIPaddress + "]" + " - " + "Connection accepted!"); await sw.FlushAsync().ConfigureAwait(false); var data = default(string); while (!((data = await sr.ReadLineAsync().ConfigureAwait(false)).Equals("exit", StringComparison.OrdinalIgnoreCase))) { await sw.WriteLineAsync(data).ConfigureAwait(false); await konus(data).ConfigureAwait(false); await sw.FlushAsync().ConfigureAwait(false); } } } } finally { if (_ownsClient && _client != null) { (_client as IDisposable).Dispose(); _client = null; RWControl.writeTofile(DateTime.Now + " - " + "[" + _clientIPaddress + "]" + " - " + "Connection disconnected!"); } } }
private async Task konus(string _gelenText) { SpeechSynthesizer synth = new SpeechSynthesizer(); synth.SetOutputToDefaultAudioDevice(); synth.Speak(_gelenText); RWControl.writeTofile(DateTime.Now + " - " + "[" + _clientIPaddress + "]" + _gelenText); }
static async Task MainAsync() { Console.WriteLine("Starting..."); var server = new TcpListener(IPAddress.Parse("0.0.0.0"), 56000); server.Start(); Console.WriteLine("Started."); RWControl.writeTofile(DateTime.Now + " - Application is started"); while (true) { var client = await server.AcceptTcpClientAsync().ConfigureAwait(false); var cw = new ClientWorking(client, true); string clientIPaddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString(); if (clientControl.IsThereAccess(clientIPaddress)) { Task.Run((Func <Task>)cw.DoClientAsync); } else { RWControl.writeTofile(DateTime.Now + "[" + clientIPaddress + "]" + " - " + "Connection rejected!"); } } }