/// <summary> /// Creates the listener and starts accepting connections over /// tcp and tcpv6. /// </summary> /// <param name="config"></param> /// <param name="controller"></param> /// <param name="logger"></param> public WebSocketChannelListener(IServer controller, IWebListenerConfig config, ILogger logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); if (controller?.Callback == null) { throw new ArgumentNullException(nameof(controller)); } _listenerId = Guid.NewGuid().ToString(); var configuration = EndpointConfiguration.Create(); _quotas = new ChannelQuotas { MaxBufferSize = configuration.MaxBufferSize, MaxMessageSize = configuration.MaxMessageSize, ChannelLifetime = configuration.ChannelLifetime, SecurityTokenLifetime = configuration.SecurityTokenLifetime, MessageContext = controller.MessageContext, CertificateValidator = controller.CertificateValidator .GetChannelValidator() }; _bufferManager = new BufferManager("Server", int.MaxValue, _quotas.MaxBufferSize); _urls = (config?.ListenUrls?.Length ?? 0) != 0 ? config.ListenUrls : new string[] { "http://localhost:9040" }; _controller = controller; }
/// <summary> /// Creates the listener and starts accepting connections over /// tcp and tcpv6. /// </summary> /// <param name="config"></param> /// <param name="controller"></param> /// <param name="logger"></param> public TcpChannelListener(IServer controller, ITcpListenerConfig config, ILogger logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _callback = controller?.Callback ?? throw new ArgumentNullException(nameof(controller)); if (config == null) { throw new ArgumentNullException(nameof(config)); } _listenerId = Guid.NewGuid().ToString(); var configuration = EndpointConfiguration.Create(); _quotas = new ChannelQuotas { MaxBufferSize = configuration.MaxBufferSize, MaxMessageSize = configuration.MaxMessageSize, ChannelLifetime = configuration.ChannelLifetime, SecurityTokenLifetime = configuration.SecurityTokenLifetime, MessageContext = controller.MessageContext, CertificateValidator = controller.CertificateValidator .GetChannelValidator() }; _serverCertificate = config.TcpListenerCertificate; _serverCertificateChain = config.TcpListenerCertificateChain; _bufferManager = new BufferManager("Server", int.MaxValue, _quotas.MaxBufferSize); _controller = controller; // Create and bind sockets for listening. var port = config.Port == 0 ? Utils.UaTcpDefaultPort : config.Port; _listeningSocket = BindSocket(IPAddress.Any, port); _listeningSocketIPv6 = BindSocket(IPAddress.IPv6Any, port); if (_listeningSocketIPv6 == null && _listeningSocket == null) { throw ServiceResultException.Create(StatusCodes.BadNoCommunication, "Failed to bind sockets for both Ipv4 and IPv6."); } var host = config.PublicDnsAddress ?? Utils.GetHostName(); EndpointUrl = new Uri($"opc.tcp://{host}:{port}"); }