예제 #1
0
        public MqttTcpServerListener(
            AddressFamily addressFamily,
            MqttServerTcpEndpointBaseOptions options,
            X509Certificate2 tlsCertificate,
            CancellationToken cancellationToken,
            IMqttNetChildLogger logger)
        {
            _cancellationToken = cancellationToken;
            _logger            = logger;

            var sb = new SocketBuilder().SetSocket(Sockets.Model.SocketType.Tcp).UseStream();

            if (options is MqttServerTlsTcpEndpointOptions tlsOptions)
            {
                sb = sb.WithSsl(tlsCertificate, tlsOptions.SslProtocol);
            }

            sb = sb.SetPort(options.Port);

            if (_addressFamily == AddressFamily.InterNetworkV6)
            {
                sb = sb.UseIPV6();
            }

            socketOption = sb.Build();

            serverSokcet = (StreamServerSocket)SocketFactory.CreateServerSocket(socketOption, cancellationToken);

            serverSokcet.OnAccepted += ServerSokcet_OnAccepted;
        }