Exemple #1
0
 public SocketListener(ListenerInfo listenerInfo)
 {
     if (listenerInfo == null)
     {
         throw new ArgumentNullException(nameof(listenerInfo));
     }
     this.info = listenerInfo;
 }
Exemple #2
0
        private void StartListeners()
        {
            List <ISocketListener> listeners = new List <ISocketListener>();

            var config = appServer.config;

            if (config.listenerConfigs == null || 0 >= config.listenerConfigs.Count)
            {
                throw new Exception("Listener list wrong");
            }

            for (int index = 0; index < config.listenerConfigs.Count; ++index)
            {
                var listenerConfig = config.listenerConfigs[index];
                if (listenerConfig == null)
                {
                    throw new Exception($"Listener({index}) is null");
                }

                if (string.IsNullOrEmpty(listenerConfig.ip))
                {
                    throw new Exception($"Listener({index}) ip is invalid");
                }

                if (0 >= listenerConfig.port)
                {
                    throw new Exception($"Listener({index}) port is invalid");
                }

                var endPoint = new IPEndPoint(SocketExtensions.ParseIPAddress(listenerConfig.ip), listenerConfig.port);

                var listenerInfo = new ListenerInfo(endPoint, listenerConfig.backlog);

                var socketListener = CreateListener(listenerInfo);
                socketListener.accepted += new ISocketListener.AcceptHandler(OnSocketAccepted);
                socketListener.error    += new ISocketListener.ErrorHandler(OnListenerError);

                socketListener.Start();
            }

            this.listeners = listeners;
        }
Exemple #3
0
 protected abstract ISocketListener CreateListener(ListenerInfo info);