Represents a ZeroMQ ROUTER style socket as a communication server.
Inheritance: ServerBase
コード例 #1
0
ファイル: ZeroMQClient.cs プロジェクト: xj0229/gsf
        /// <summary>
        /// Raises the <see cref="ClientBase.UnhandledUserException"/> event.
        /// </summary>
        /// <param name="ex">Exception to send to <see cref="ClientBase.UnhandledUserException"/> event.</param>
        protected override void OnUnhandledUserException(Exception ex)
        {
            if (ZeroMQServer.IsThreadAbortException(ex))
            {
                return;
            }

            base.OnUnhandledUserException(ex);
        }
コード例 #2
0
ファイル: ZeroMQClient.cs プロジェクト: xj0229/gsf
        /// <summary>
        /// Raises the <see cref="ClientBase.SendDataException"/> event for disconnect exceptions.
        /// </summary>
        /// <param name="ex">Disconnect exception to send to <see cref="ClientBase.SendDataException"/> event.</param>
        protected virtual void OnDisconnectException(Exception ex)
        {
            if (ZeroMQServer.IsThreadAbortException(ex))
            {
                return;
            }

            OnSendDataException(new InvalidOperationException($"Disconnect exception: {ex.Message}", ex));
        }
コード例 #3
0
ファイル: ZeroMQClient.cs プロジェクト: xj0229/gsf
        /// <summary>
        /// Raises the <see cref="ClientBase.ConnectionException"/> event.
        /// </summary>
        /// <param name="ex">Exception to send to <see cref="ClientBase.ConnectionException"/> event.</param>
        protected override void OnConnectionException(Exception ex)
        {
            if (ZeroMQServer.IsThreadAbortException(ex))
            {
                return;
            }

            base.OnConnectionException(ex);
        }
コード例 #4
0
ファイル: ZeroMQClient.cs プロジェクト: xj0229/gsf
        /// <summary>
        /// Raises the <see cref="ClientBase.ReceiveDataException"/> event.
        /// </summary>
        /// <param name="ex">Exception to send to <see cref="ClientBase.ReceiveDataException"/> event.</param>
        protected override void OnReceiveDataException(Exception ex)
        {
            if (ZeroMQServer.IsThreadAbortException(ex))
            {
                return;
            }

            if (CurrentState != ClientState.Disconnected)
            {
                base.OnReceiveDataException(ex);
            }
        }
コード例 #5
0
ファイル: ZeroMQClient.cs プロジェクト: xj0229/gsf
        /// <summary>
        /// Raises the <see cref="ClientBase.SendDataException"/> event.
        /// </summary>
        /// <param name="ex">Exception to send to <see cref="ClientBase.SendDataException"/> event.</param>
        protected override void OnSendDataException(Exception ex)
        {
            if (ZeroMQServer.IsThreadAbortException(ex))
            {
                return;
            }

            if (CurrentState != ClientState.Disconnected)
            {
                ZException zmqex = ex as ZException;

                if ((object)zmqex != null && (zmqex.ErrNo == ZError.EAGAIN || zmqex.ErrNo == ZError.ETERM))
                {
                    ThreadPool.QueueUserWorkItem(state => Disconnect());
                }
                else
                {
                    base.OnSendDataException(ex);
                }
            }
        }
コード例 #6
0
ファイル: ServerBase.cs プロジェクト: avs009/gsf
        /// <summary>
        /// Create a communications server
        /// </summary>
        /// <remarks>
        /// Note that typical configuration string should be prefixed with a "protocol=tcp" or a "protocol=udp"
        /// </remarks>
        /// <param name="configurationString">The configuration string for the server.</param>
        /// <returns>A communications server.</returns>
        public static IServer Create(string configurationString)
        {
            Dictionary<string, string> configurationSettings = configurationString.ParseKeyValuePairs();
            IServer server;
            string protocol;

            if (configurationSettings.TryGetValue("protocol", out protocol))
            {
                configurationSettings.Remove("protocol");
                StringBuilder settings = new StringBuilder();

                foreach (string key in configurationSettings.Keys)
                {
                    settings.Append(key);
                    settings.Append("=");
                    settings.Append(configurationSettings[key]);
                    settings.Append(";");
                }

                // Create a server instance for the specified protocol.
                switch (protocol.Trim().ToLower())
                {
                    case "tls":
                        server = new TlsServer(settings.ToString());
                        break;
                    case "tcp":
                        server = new TcpServer(settings.ToString());
                        break;
                    case "udp":
                        server = new UdpServer(settings.ToString());
                        break;
                    case "zeromq":
                        server = new ZeroMQServer(settings.ToString());
                        break;
                    default:
                        throw new ArgumentException("Transport protocol \'" + protocol + "\' is not valid");
                }

                // Apply server settings from the connection string to the client.
                foreach (KeyValuePair<string, string> setting in configurationSettings)
                {
                    PropertyInfo property = server.GetType().GetProperty(setting.Key);
                    if (property != null)
                        property.SetValue(server, Convert.ChangeType(setting.Value, property.PropertyType), null);
                }
            }
            else
            {
                throw new ArgumentException("Transport protocol must be specified");
            }

            return server;
        }