Ejemplo n.º 1
0
        private ServerCore()
        {
            LoadConfig();
            RegisterCommanders();
            try
            {
                sqlConnecter = SqlConnector.Instance;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not connect to Mysql: \"" + ex.Message + "\"");
                Console.WriteLine("Aborting. Press any key to exit");
                Console.Read();
                return;
            }
            idConnection = new Dictionary<UInt32, TcpClient>();
            connectionWorker = new Dictionary<TcpClient, ClientWorker>();
            connectionId = new Dictionary<TcpClient, UInt32>();
            workers = new List<ClientWorker>();
            TcpListener tcpListener = new System.Net.Sockets.TcpListener(IPAddress.Parse(ip), port);

            tcpListener.Start();
            while (true)
            {
                TcpClient connection = tcpListener.AcceptTcpClient();
                Console.WriteLine("Someone connected");
                ClientWorker worker = new ClientWorker(connection);
                lock (mutex)
                {
                    connectionWorker.Add(connection, worker);
                    workers.Add(worker);
                }
            }
        }
Ejemplo n.º 2
0
        private ServerCore()
        {
            LoadConfig();
            RegisterCommanders();
            try
            {
                sqlConnecter = SqlConnector.Instance;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not connect to Mysql: \"" + ex.Message + "\"");
                Console.WriteLine("Aborting. Press any key to exit");
                Console.Read();
                return;
            }
            idConnection     = new Dictionary <UInt32, TcpClient>();
            connectionWorker = new Dictionary <TcpClient, ClientWorker>();
            connectionId     = new Dictionary <TcpClient, UInt32>();
            workers          = new List <ClientWorker>();
            TcpListener tcpListener = new System.Net.Sockets.TcpListener(IPAddress.Parse(ip), port);

            tcpListener.Start();
            while (true)
            {
                TcpClient connection = tcpListener.AcceptTcpClient();
                Console.WriteLine("Someone connected");
                ClientWorker worker = new ClientWorker(connection);
                lock (mutex)
                {
                    connectionWorker.Add(connection, worker);
                    workers.Add(worker);
                }
            }
        }