/// <summary>
 /// Initializes a new instance of the <see cref="ZeroMQClient"/> class.
 /// </summary>
 /// <param name="connectString">Connect string of the <see cref="ZeroMQClient"/>. See <see cref="DefaultConnectionString"/> for format.</param>
 public ZeroMQClient(string connectString) : base(TransportProtocol.Tcp, connectString)
 {
     m_zeroMQClient            = new();
     m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;
     m_completedHandle         = new(true);
     MaxSendQueueSize          = DefaultMaxSendQueueSize;
     MaxReceiveQueueSize       = DefaultMaxReceiveQueueSize;
     m_sendLock = new();
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZeroMQClient"/> class.
 /// </summary>
 /// <param name="connectString">Connect string of the <see cref="ZeroMQClient"/>. See <see cref="DefaultConnectionString"/> for format.</param>
 public ZeroMQClient(string connectString) : base(TransportProtocol.Tcp, connectString)
 {
     m_zeroMQClient            = new TransportProvider <ZSocket>();
     m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;
     m_completedHandle         = new ManualResetEventSlim(true);
     MaxSendQueueSize          = DefaultMaxSendQueueSize;
     MaxReceiveQueueSize       = DefaultMaxReceiveQueueSize;
     m_sendLock = new object();
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZeroMQServer"/> class.
 /// </summary>
 /// <param name="configString">Config string of the <see cref="ZeroMQServer"/>. See <see cref="DefaultConfigurationString"/> for format.</param>
 public ZeroMQServer(string configString) : base(TransportProtocol.Tcp, configString)
 {
     m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;
     m_completedHandle         = new ManualResetEventSlim(true);
     MaxSendQueueSize          = DefaultMaxSendQueueSize;
     MaxReceiveQueueSize       = DefaultMaxReceiveQueueSize;
     m_clientInfoLookup        = new ConcurrentDictionary <Guid, TransportProvider <DateTime> >();
     m_activeClientTimer       = new Timer(MonitorActiveClients, null, TimeSpan.FromMinutes(1.0D), TimeSpan.FromMinutes(1.0D));
     m_sendLock = new object();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ZeroMQServer"/> class.
 /// </summary>
 /// <param name="configString">Config string of the <see cref="ZeroMQServer"/>. See <see cref="DefaultConfigurationString"/> for format.</param>
 public ZeroMQServer(string configString) : base(TransportProtocol.Tcp, configString)
 {
     m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;
     m_completedHandle         = new(true);
     MaxSendQueueSize          = DefaultMaxSendQueueSize;
     MaxReceiveQueueSize       = DefaultMaxReceiveQueueSize;
     m_clientInfoLookup        = new();
     m_activeClientTimer       = new(MonitorActiveClients, null, TimeSpan.FromMinutes(1.0D), TimeSpan.FromMinutes(1.0D));
     m_sendLock = new();
 }
示例#5
0
        /// <summary>
        /// Validates the specified <paramref name="configurationString"/>.
        /// </summary>
        /// <param name="configurationString">Configuration string to be validated.</param>
        /// <exception cref="ArgumentException">Port property is missing.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Port property value is not between <see cref="Transport.PortRangeLow"/> and <see cref="Transport.PortRangeHigh"/>.</exception>
        protected override void ValidateConfigurationString(string configurationString)
        {
            m_configData = configurationString.ParseKeyValuePairs();

            // Check for "server" property, this is the preferred configuration for ZeroMQServer
            if (m_configData.ContainsKey("server"))
            {
                // Validate ZeroMQ configuration string
                Match  endpointMatch            = Regex.Match(m_configData["server"], EndpointFormatRegex);
                string port                     = null;
                bool   validConfigurationString = false;

                if (endpointMatch.Success)
                {
                    if (!Enum.TryParse(endpointMatch.Groups["protocol"].Value.Trim(), true, out m_zeroMQTransportProtocol))
                    {
                        m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;
                    }

                    m_configData["interface"] = endpointMatch.Groups["host"].Value.Trim();
                    port = endpointMatch.Groups["port"].Value.Trim();
                    validConfigurationString = true;
                }
                else
                {
                    // Support traditional IClient "server" property
                    endpointMatch = Regex.Match(m_configData["server"], Transport.EndpointFormatRegex);

                    if (endpointMatch.Success)
                    {
                        m_configData["server"]    = $"{m_zeroMQTransportProtocol.ToString().ToLowerInvariant()}://{m_configData["server"]}";
                        m_configData["interface"] = endpointMatch.Groups["host"].Value.Trim();
                        port = endpointMatch.Groups["port"].Value.Trim();
                        validConfigurationString = true;
                    }
                }

                if (!validConfigurationString)
                {
                    throw new FormatException($"Server property is invalid (Example: {DefaultConfigurationString})");
                }

                if (m_zeroMQTransportProtocol != ZeroMQTransportProtocol.InProc && !Transport.IsPortNumberValid(port))
                {
                    throw new ArgumentOutOfRangeException(nameof(configurationString), $"Port number must be between {Transport.PortRangeLow} and {Transport.PortRangeHigh}");
                }
            }
            else
            {
                // Fall back on traditional server configuration strings
                Transport.GetInterfaceIPStack(m_configData);

                if (string.IsNullOrWhiteSpace(m_configData["interface"]) || m_configData["interface"].Equals("0.0.0.0", StringComparison.Ordinal))
                {
                    m_configData["interface"] = "*";
                }

                // For traditional style connection strings, also support a "zeroMQTransportProtocol" setting
                if (m_configData.ContainsKey("zeroMQTransportProtocol"))
                {
                    ZeroMQTransportProtocol protocol;

                    if (Enum.TryParse(m_configData["zeroMQTransportProtocol"].Trim(), true, out protocol))
                    {
                        m_zeroMQTransportProtocol = protocol;
                    }
                }

                // For traditional IServer connection strings, a "port" property is expected
                if (m_configData.ContainsKey("port") && m_zeroMQTransportProtocol != ZeroMQTransportProtocol.InProc)
                {
                    m_configData["server"] = $"{m_zeroMQTransportProtocol.ToString().ToLowerInvariant()}://{m_configData["interface"]}:{m_configData["port"]}";
                }
                else
                {
                    throw new FormatException($"Server property is invalid (Example: {DefaultConfigurationString})");
                }
            }
        }
示例#6
0
        /// <summary>
        /// Validates the specified <paramref name="connectionString"/>.
        /// </summary>
        /// <param name="connectionString">Connection string to be validated.</param>
        /// <exception cref="ArgumentException">Server property is missing.</exception>
        /// <exception cref="FormatException">Server property is invalid.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Server port value is not between <see cref="Transport.PortRangeLow"/> and <see cref="Transport.PortRangeHigh"/>.</exception>
        protected override void ValidateConnectionString(string connectionString)
        {
            m_connectData = connectionString.ParseKeyValuePairs();

            // Make sure "interface" setting exists
            Transport.GetInterfaceIPStack(m_connectData);

            // Check if 'server' property is missing.
            if (!m_connectData.ContainsKey("server"))
            {
                throw new ArgumentException($"Server property is missing (Example: {DefaultConnectionString})");
            }

            // Backwards compatibility adjustments.
            // New Format: Server=localhost:8888
            // Old Format: Server=localhost; Port=8888
            if (m_connectData.ContainsKey("port"))
            {
                m_connectData["server"] = $"{m_connectData["server"]}:{m_connectData["port"]}";
            }

            // For traditional style connection strings, also support a "zeroMQTransportProtocol" setting
            if (m_connectData.ContainsKey("zeroMQTransportProtocol"))
            {
                ZeroMQTransportProtocol protocol;

                if (Enum.TryParse(m_connectData["zeroMQTransportProtocol"].Trim(), true, out protocol))
                {
                    m_zeroMQTransportProtocol = protocol;
                }
            }

            // Validate ZeroMQ connection string
            Match  endpointMatch         = Regex.Match(m_connectData["server"], ZeroMQServer.EndpointFormatRegex);
            string port                  = null;
            bool   validConnectionString = false;

            if (endpointMatch.Success)
            {
                if (!Enum.TryParse(endpointMatch.Groups["protocol"].Value.Trim(), true, out m_zeroMQTransportProtocol))
                {
                    m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;
                }

                port = endpointMatch.Groups["port"].Value.Trim();
                validConnectionString = true;

                if (!string.IsNullOrWhiteSpace(m_connectData["interface"]) && (m_zeroMQTransportProtocol == ZeroMQTransportProtocol.Pgm || m_zeroMQTransportProtocol == ZeroMQTransportProtocol.Epgm))
                {
                    m_connectData["server"] = $"{m_zeroMQTransportProtocol.ToString().ToLowerInvariant()}://{m_connectData["interface"]};{endpointMatch.Groups["host"].Value.Trim()}:{port}";
                }
            }
            else
            {
                // Support traditional IClient "server" property
                endpointMatch = Regex.Match(m_connectData["server"], Transport.EndpointFormatRegex);

                if (endpointMatch.Success)
                {
                    m_connectData["server"] = $"{m_zeroMQTransportProtocol.ToString().ToLowerInvariant()}://{m_connectData["server"]}";
                    port = endpointMatch.Groups["port"].Value.Trim();
                    validConnectionString = true;

                    if (!string.IsNullOrWhiteSpace(m_connectData["interface"]) && (m_zeroMQTransportProtocol == ZeroMQTransportProtocol.Pgm || m_zeroMQTransportProtocol == ZeroMQTransportProtocol.Epgm))
                    {
                        m_connectData["server"] = $"{m_zeroMQTransportProtocol.ToString().ToLowerInvariant()}://{m_connectData["interface"]};{endpointMatch.Groups["host"].Value.Trim()}:{port}";
                    }
                }
            }

            if (!validConnectionString)
            {
                throw new FormatException($"Server property is invalid (Example: {DefaultConnectionString})");
            }

            if (m_zeroMQTransportProtocol != ZeroMQTransportProtocol.InProc && !Transport.IsPortNumberValid(port))
            {
                throw new ArgumentOutOfRangeException(nameof(connectionString), $"Server port must between {Transport.PortRangeLow} and {Transport.PortRangeHigh}");
            }
        }
示例#7
0
文件: ZeroMQServer.cs 项目: rmc00/gsf
        /// <summary>
        /// Validates the specified <paramref name="configurationString"/>.
        /// </summary>
        /// <param name="configurationString">Configuration string to be validated.</param>
        /// <exception cref="ArgumentException">Port property is missing.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Port property value is not between <see cref="Transport.PortRangeLow"/> and <see cref="Transport.PortRangeHigh"/>.</exception>
        protected override void ValidateConfigurationString(string configurationString)
        {
            m_configData = configurationString.ParseKeyValuePairs();

            // Check for "server" property, this is the preferred configuration for ZeroMQServer
            if (m_configData.ContainsKey("server"))
            {
                // Validate ZeroMQ configuration string
                Match endpointMatch = Regex.Match(m_configData["server"], EndpointFormatRegex);
                string port = null;
                bool validConfigurationString = false;

                if (endpointMatch.Success)
                {
                    if (!Enum.TryParse(endpointMatch.Groups["protocol"].Value.Trim(), true, out m_zeroMQTransportProtocol))
                        m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;

                    m_configData["interface"] = endpointMatch.Groups["host"].Value.Trim();
                    port = endpointMatch.Groups["port"].Value.Trim();
                    validConfigurationString = true;
                }
                else
                {
                    // Support traditional IClient "server" property
                    endpointMatch = Regex.Match(m_configData["server"], Transport.EndpointFormatRegex);

                    if (endpointMatch.Success)
                    {
                        m_configData["server"] = string.Format("{0}://{1}", m_zeroMQTransportProtocol.ToString().ToLowerInvariant(), m_configData["server"]);
                        m_configData["interface"] = endpointMatch.Groups["host"].Value.Trim();
                        port = endpointMatch.Groups["port"].Value.Trim();
                        validConfigurationString = true;
                    }
                }

                if (!validConfigurationString)
                    throw new FormatException(string.Format("Server property is invalid (Example: {0})", DefaultConfigurationString));

                if (m_zeroMQTransportProtocol != ZeroMQTransportProtocol.InProc && !Transport.IsPortNumberValid(port))
                    throw new ArgumentOutOfRangeException("configurationString", string.Format("Port number must be between {0} and {1}", Transport.PortRangeLow, Transport.PortRangeHigh));
            }
            else
            {
                // Fall back on traditional server configuration strings
                Transport.GetInterfaceIPStack(m_configData);

                if (string.IsNullOrWhiteSpace(m_configData["interface"]) || m_configData["interface"].Equals("0.0.0.0", StringComparison.Ordinal))
                    m_configData["interface"] = "*";

                // For traditional style connection strings, also support a "zeroMQTransportProtocol" setting
                if (m_configData.ContainsKey("zeroMQTransportProtocol"))
                {
                    ZeroMQTransportProtocol protocol;

                    if (Enum.TryParse(m_configData["zeroMQTransportProtocol"].Trim(), true, out protocol))
                        m_zeroMQTransportProtocol = protocol;
                }

                // For traditional IServer connection strings, a "port" property is expected
                if (m_configData.ContainsKey("port") && m_zeroMQTransportProtocol != ZeroMQTransportProtocol.InProc)
                    m_configData["server"] = string.Format("{0}://{1}:{2}", m_zeroMQTransportProtocol.ToString().ToLowerInvariant(), m_configData["interface"], m_configData["port"]);
                else
                    throw new FormatException(string.Format("Server property is invalid (Example: {0})", DefaultConfigurationString));
            }
        }
示例#8
0
文件: ZeroMQServer.cs 项目: rmc00/gsf
 /// <summary>
 /// Initializes a new instance of the <see cref="ZeroMQServer"/> class.
 /// </summary>
 /// <param name="configString">Config string of the <see cref="ZeroMQServer"/>. See <see cref="DefaultConfigurationString"/> for format.</param>
 public ZeroMQServer(string configString)
     : base(TransportProtocol.Tcp, configString)
 {
     m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;
     m_completedHandle = new ManualResetEventSlim(true);
     m_maxSendQueueSize = DefaultMaxSendQueueSize;
     m_maxReceiveQueueSize = DefaultMaxReceiveQueueSize;
     m_clientInfoLookup = new ConcurrentDictionary<Guid, TransportProvider<DateTime>>();
     m_activeClientTimer = new Timer(MonitorActiveClients, null, TimeSpan.FromMinutes(1.0D), TimeSpan.FromMinutes(1.0D));
     m_sendLock = new object();
 }
        /// <summary>
        /// Validates the specified <paramref name="connectionString"/>.
        /// </summary>
        /// <param name="connectionString">Connection string to be validated.</param>
        /// <exception cref="ArgumentException">Server property is missing.</exception>
        /// <exception cref="FormatException">Server property is invalid.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Server port value is not between <see cref="Transport.PortRangeLow"/> and <see cref="Transport.PortRangeHigh"/>.</exception>
        protected override void ValidateConnectionString(string connectionString)
        {
            m_connectData = connectionString.ParseKeyValuePairs();

            // Make sure "interface" setting exists
            Transport.GetInterfaceIPStack(m_connectData);

            // Check if 'server' property is missing.
            if (!m_connectData.ContainsKey("server"))
                throw new ArgumentException($"Server property is missing (Example: {DefaultConnectionString})");

            // Backwards compatibility adjustments.
            // New Format: Server=localhost:8888
            // Old Format: Server=localhost; Port=8888
            if (m_connectData.ContainsKey("port"))
                m_connectData["server"] = $"{m_connectData["server"]}:{m_connectData["port"]}";

            // For traditional style connection strings, also support a "zeroMQTransportProtocol" setting
            if (m_connectData.ContainsKey("zeroMQTransportProtocol"))
            {
                ZeroMQTransportProtocol protocol;

                if (Enum.TryParse(m_connectData["zeroMQTransportProtocol"].Trim(), true, out protocol))
                    m_zeroMQTransportProtocol = protocol;
            }

            // Validate ZeroMQ connection string
            Match endpointMatch = Regex.Match(m_connectData["server"], ZeroMQServer.EndpointFormatRegex);
            string port = null;
            bool validConnectionString = false;

            if (endpointMatch.Success)
            {
                if (!Enum.TryParse(endpointMatch.Groups["protocol"].Value.Trim(), true, out m_zeroMQTransportProtocol))
                    m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;

                port = endpointMatch.Groups["port"].Value.Trim();
                validConnectionString = true;

                if (!string.IsNullOrWhiteSpace(m_connectData["interface"]) && (m_zeroMQTransportProtocol == ZeroMQTransportProtocol.Pgm || m_zeroMQTransportProtocol == ZeroMQTransportProtocol.Epgm))
                    m_connectData["server"] = $"{m_zeroMQTransportProtocol.ToString().ToLowerInvariant()}://{m_connectData["interface"]};{endpointMatch.Groups["host"].Value.Trim()}:{port}";
            }
            else
            {
                // Support traditional IClient "server" property
                endpointMatch = Regex.Match(m_connectData["server"], Transport.EndpointFormatRegex);

                if (endpointMatch.Success)
                {
                    m_connectData["server"] = $"{m_zeroMQTransportProtocol.ToString().ToLowerInvariant()}://{m_connectData["server"]}";
                    port = endpointMatch.Groups["port"].Value.Trim();
                    validConnectionString = true;

                    if (!string.IsNullOrWhiteSpace(m_connectData["interface"]) && (m_zeroMQTransportProtocol == ZeroMQTransportProtocol.Pgm || m_zeroMQTransportProtocol == ZeroMQTransportProtocol.Epgm))
                        m_connectData["server"] = $"{m_zeroMQTransportProtocol.ToString().ToLowerInvariant()}://{m_connectData["interface"]};{endpointMatch.Groups["host"].Value.Trim()}:{port}";
                }
            }

            if (!validConnectionString)
                throw new FormatException($"Server property is invalid (Example: {DefaultConnectionString})");

            if (m_zeroMQTransportProtocol != ZeroMQTransportProtocol.InProc && !Transport.IsPortNumberValid(port))
                throw new ArgumentOutOfRangeException(nameof(connectionString), $"Server port must between {Transport.PortRangeLow} and {Transport.PortRangeHigh}");
        }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZeroMQClient"/> class.
 /// </summary>
 /// <param name="connectString">Connect string of the <see cref="ZeroMQClient"/>. See <see cref="DefaultConnectionString"/> for format.</param>
 public ZeroMQClient(string connectString)
     : base(TransportProtocol.Tcp, connectString)
 {
     m_zeroMQClient = new TransportProvider<ZSocket>();
     m_zeroMQTransportProtocol = ZeroMQTransportProtocol.Tcp;
     m_completedHandle = new ManualResetEventSlim(true);
     m_maxSendQueueSize = DefaultMaxSendQueueSize;
     m_maxReceiveQueueSize = DefaultMaxReceiveQueueSize;
     m_sendLock = new object();
 }