private string EveInterpretate(string message, ClientObject client) { try { Task.Run(() => client.GetMessage()); string teg = message.Substring(0, message.IndexOf(';')); message = message.Remove(0, message.IndexOf(';') + 1); switch (teg) { case "Message": //Send message for user { return(message); } case "Readiness": //Readiness player { client.readiness = !client.readiness; if (client.readiness) { ++readinessPlayers; } else { --readinessPlayers; } Play(); break; } case "Rate": //Get rate { double rat = Math.Round(double.Parse(message), 2); client.rate += rat; client.many -= rat; bank += rat; if (clientsList.Last().id == client.id) { NextRound(); } break; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(null); }
internal void Listener() { try { tcpListener = new TcpListener(IPAddress.Parse(ip), port); tcpListener.Start(); while (true) { TcpClient tcpClient = tcpListener.AcceptTcpClient(); ClientObject clientObject = new ClientObject(tcpClient, this); clientObject.eventGetMessage += EveInterpretate; clientsList.Add(clientObject); Task.Run(() => { clientObject.GetMessage(); }); //Thread thread = new Thread(() => { clientObject.GetMessage(); }); //thread.Start(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }