Exemple #1
0
        public virtual void Start(ListenerConfig cnfg, ILogger lger)
        {
            if (cnfg == null)
            {
                throw new ArgumentNullException(nameof(cnfg));
            }

            if (lger == null)
            {
                throw new ArgumentNullException(nameof(lger));
            }

            if (string.IsNullOrEmpty(cnfg.ip))
            {
                throw new ArgumentNullException(nameof(cnfg.ip));
            }

            if (0 > cnfg.port || short.MaxValue < cnfg.port)
            {
                throw new ArgumentException("Invalid Port Range");
            }

            config = cnfg;
            logger = lger;

            if (accepted == null)
            {
                logger.Warn("Accepted Handler is not set : Unable to receive events for socket accept");
            }

            if (error == null)
            {
                this.logger.Warn("Error Handler is not set : Unable to receive events for error");
            }
        }
Exemple #2
0
        public override void Start(ListenerConfig cnfg, ILogger lger)
        {
            base.Start(cnfg, lger);

            _cancellationToken = new CancellationTokenSource();

            IPEndPoint endPoint = new IPEndPoint(ParseAddress(this.config.ip), this.config.port);

            _listenSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
            _listenSocket.Bind(endPoint);
            _listenSocket.Listen(this.config.backlog);

            _acceptLoopTask = AcceptLoop();
        }