Beispiel #1
0
 /// <summary>
 ///     Create a new NetMQSocket with the given <see cref="SocketBase" />.
 /// </summary>
 /// <param name="socketHandle">a SocketBase object to assign to the new socket</param>
 internal NetMQSocket([NotNull] SocketBase socketHandle)
 {
     this.m_netMqSelector   = new NetMQSelector();
     this.SocketHandle      = socketHandle;
     this.Options           = new SocketOptions(this);
     this.m_socketEventArgs = new NetMQSocketEventArgs(this);
 }
Beispiel #2
0
        /// <summary>
        ///     Create a new NetMQSocket with the given <see cref="ZmqSocketType" />.
        /// </summary>
        /// <param name="socketType">Type of socket to create</param>
        /// <param name="connectionString"></param>
        /// <param name="defaultAction"></param>
        internal NetMQSocket(ZmqSocketType socketType, string connectionString, DefaultAction defaultAction)
        {
            this.SocketHandle      = NetMQConfig.Context.CreateSocket(socketType);
            this.m_netMqSelector   = new NetMQSelector();
            this.Options           = new SocketOptions(this);
            this.m_socketEventArgs = new NetMQSocketEventArgs(this);

            this.Options.Linger = NetMQConfig.Linger;

            if (!string.IsNullOrEmpty(connectionString))
            {
                IEnumerable <string> endpoints =
                    connectionString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(a => a.Trim()).Where(a => !string.IsNullOrEmpty(a));

                foreach (string endpoint in endpoints)
                {
                    if (endpoint[0] == '@')
                    {
                        this.Bind(endpoint.Substring(1));
                    }
                    else if (endpoint[0] == '>')
                    {
                        this.Connect(endpoint.Substring(1));
                    }
                    else if (defaultAction == DefaultAction.Connect)
                    {
                        this.Connect(endpoint);
                    }
                    else
                    {
                        this.Bind(endpoint);
                    }
                }
            }
        }