Represents a ZeroMQ ROUTER style socket as a communication server.
Inheritance: ServerBase
Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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));
        }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
        /// <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);
            }
        }
Exemple #5
0
        /// <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);
                }
            }
        }
Exemple #6
0
        /// <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;
        }