Ejemplo n.º 1
0
        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());
            }
        }
Ejemplo n.º 2
0
        public void ExecuteRequest()
        {
            StreamReader reader = new StreamReader(TcpHandler.GetStream(Client));

            Context        = new ContextManager(reader);
            RequestManager = new RequestManager(Context);
            SendResponse(RequestManager.ProcessRequest());
        }
Ejemplo n.º 3
0
 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());
 }
Ejemplo n.º 4
0
 public void CloseClient()
 {
     TcpHandler.CloseClient(Client);
 }