public static void Main() { //Preparing the Threads TcpHandler tcpHandler = null; var tasks = new List <Task>(); try { //Using Port 10001 and allowing the default 5 clients in the queue tcpHandler = new TcpHandler(10001); while (true) { //Starting the Threads ConcurrentConnections.Wait(); tasks.Add(Task.Run(() => ReceiveClient(tcpHandler))); } } //Hopefully no Exceptions here catch (Exception e) { Console.WriteLine(e); throw; } finally { //When finished stop the Server and set all threads on hold tcpHandler?.Stop(); Task.WaitAll(tasks.ToArray()); } }
public void ExecuteRequest() { StreamReader reader = new StreamReader(TcpHandler.GetStream(Client)); Context = new ContextManager(reader); RequestManager = new RequestManager(Context); SendResponse(RequestManager.ProcessRequest()); }
public void SendResponse(IResponse response) { ResponseManager = new ResponseManager(response, "MonsterTCG-Server"); using StreamWriter writer = new StreamWriter(TcpHandler.GetStream(Client)) { AutoFlush = true }; writer.WriteLine(ResponseManager.ProcessResponse()); }
public void CloseClient() { TcpHandler.CloseClient(Client); }