private void StartListener(object obj)
        {
            ExtendedListener listener = (ExtendedListener)obj;

            try
            {
                listener.Listener.Listen(100);
                logger.Info("[NetworkComponent] Server for {type} was started with IP: {ip}", listener.ClientType, listener.Listener.LocalEndPoint);

                while (true)
                {
                    listener.Barrier.Reset();
                    listener.Listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
                    listener.Barrier.WaitOne();

                    if (listener.ClientType == ClientType.GameMaster)
                    {
                        break;
                    }
                }
            }
            catch (SocketException e)
            {
                server.RaiseException(new CommunicationErrorException(CommunicationExceptionType.SocketNotCreated, e));
            }
        }
        internal void StartListening(Socket gameMasterListener, Socket agentListener)
        {
            gameMasterSocket = gameMasterListener;
            agentSocket      = agentListener;

            var gameMasterPort = server.Configuration.GameMasterPort;
            var agentPort      = server.Configuration.AgentPort;

            var gameMasterEndpoint = new IPEndPoint(server.IPAddress, gameMasterPort);
            var agentEndpoint      = new IPEndPoint(server.IPAddress, agentPort);

            var extendedGameMasterListener = new ExtendedListener(gameMasterListener, ClientType.GameMaster, ref gmAccepted);
            var extendedAgentListener      = new ExtendedListener(agentListener, ClientType.Agent, ref agentAccepted);

            try
            {
                gameMasterListener.Bind(gameMasterEndpoint);
                agentListener.Bind(agentEndpoint);

                var gameMasterTask = new Task(StartListener, extendedGameMasterListener);
                gameMasterTask.Start();

                var agentsTask = new Task(StartListener, extendedAgentListener);
                agentsTask.Start();
            }
            catch (ArgumentNullException e)
            {
                throw new CommunicationErrorException(CommunicationExceptionType.InvalidEndpoint, e);
            }
            catch (ArgumentOutOfRangeException e)
            {
                throw new CommunicationErrorException(CommunicationExceptionType.InvalidEndpoint, e);
            }
            catch (SocketException e)
            {
                throw new CommunicationErrorException(CommunicationExceptionType.SocketNotCreated, e);
            }
            catch (ObjectDisposedException e)
            {
                throw new CommunicationErrorException(CommunicationExceptionType.SocketNotCreated, e);
            }
        }