public Dictionary <string, Dictionary <string, bool> > Broadping(string message)
        {
            if (_state != ServerState.Start)
            {
                var msg = "The current state of the manager is not Start.";
                throw new InvalidOperationException(msg);
            }

            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            byte[] bytes;
            if (!message.TryGetUTF8EncodedBytes(out bytes))
            {
                var msg = "It could not be UTF-8-encoded.";
                throw new ArgumentException(msg, "message");
            }

            if (bytes.Length > 125)
            {
                var msg = "Its size is greater than 125 bytes.";
                throw new ArgumentOutOfRangeException("message", msg);
            }

            var frame = WebSocketFrame.CreatePingFrame(bytes, false);

            return(broadping(frame.ToArray(), _waitTime));
        }
Пример #2
0
        /// <summary>
        /// Sends a Ping with the specified <paramref name="message"/> to every client
        /// in the WebSocket services.
        /// </summary>
        /// <returns>
        /// A <c>Dictionary&lt;string, Dictionary&lt;string, bool&gt;&gt;</c> that contains
        /// a collection of pairs of a service path and a collection of pairs of a session ID
        /// and a value indicating whether the manager received a Pong from each client in a time,
        /// or <see langword="null"/> if this method isn't available or <paramref name="message"/>
        /// is invalid.
        /// </returns>
        /// <param name="message">
        /// A <see cref="string"/> that represents the message to send.
        /// </param>
        public async Task <IDictionary <string, IDictionary <string, bool> > > Broadping(string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                return(await Broadping().ConfigureAwait(false));
            }

            byte[] data = null;
            var    msg  = _state.CheckIfStart() ??
                          (data = Encoding.UTF8.GetBytes(message)).CheckIfValidControlData("message");

            return(msg != null
                ? new Dictionary <string, IDictionary <string, bool> >()
                : await Broadping(await WebSocketFrame.CreatePingFrame(data, false).ToByteArray().ConfigureAwait(false), _waitTime).ConfigureAwait(false));
        }
        public Dictionary <string, bool> Broadping(string message)
        {
            if (message == null || message.Length == 0)
            {
                return(Broadping());
            }
            byte[] data = null;
            string text = _state.CheckIfStart() ?? (data = Encoding.UTF8.GetBytes(message)).CheckIfValidControlData("message");

            if (text != null)
            {
                _logger.Error(text);
                return(null);
            }
            return(Broadping(WebSocketFrame.CreatePingFrame(data, mask: false).ToByteArray(), _waitTime));
        }
Пример #4
0
        /// <summary>
        /// Sends a Ping with the specified <paramref name="message"/> to every client in
        /// the WebSocket service.
        /// </summary>
        /// <returns>
        /// A <c>Dictionary&lt;string, bool&gt;</c> that contains a collection of pairs of
        /// a session ID and a value indicating whether the manager received a Pong from
        /// each client in a time.
        /// </returns>
        /// <param name="message">
        /// A <see cref="string"/> that represents the message to send.
        /// </param>
        public Dictionary <string, bool> Broadping(string message)
        {
            if (message == null || message.Length == 0)
            {
                return(Broadping());
            }

            byte[] data = null;
            var    msg  = _state.CheckIfAvailable(false, true, false) ?? WebSocket.CheckPingParameter(message, out data);

            if (msg != null)
            {
                _logger.Error(msg);
                return(null);
            }

            return(Broadping(WebSocketFrame.CreatePingFrame(data, false).ToArray(), _waitTime));
        }
Пример #5
0
        /// <summary>
        /// Sends a Ping with the specified <paramref name="message"/> to every client in the WebSocket
        /// service.
        /// </summary>
        /// <returns>
        /// A Dictionary&lt;string, bool&gt; that contains the collection of pairs of session ID and
        /// value indicating whether the manager received a Pong from every client in a time.
        /// </returns>
        /// <param name="message">
        /// A <see cref="string"/> that represents the message to send.
        /// </param>
        public Dictionary <string, bool> Broadping(string message)
        {
            if (message == null || message.Length == 0)
            {
                return(Broadping());
            }

            byte [] data = null;
            var     msg  = _state.CheckIfStart() ??
                           (data = Encoding.UTF8.GetBytes(message)).CheckIfValidControlData("message");

            if (msg != null)
            {
                _logger.Error(msg);
                return(null);
            }

            return(Broadping(WebSocketFrame.CreatePingFrame(Mask.Unmask, data).ToByteArray(), 1000));
        }
        public Dictionary <string, Dictionary <string, bool> > Broadping(string message)
        {
            Dictionary <string, Dictionary <string, bool> > strs;

            if ((message == null ? false : message.Length != 0))
            {
                byte[] numArray = null;
                string str      = ((ServerState)this._state).CheckIfAvailable(false, true, false) ?? WebSocket.CheckPingParameter(message, out numArray);
                if (str == null)
                {
                    strs = this.broadping(WebSocketFrame.CreatePingFrame(numArray, false).ToArray(), this._waitTime);
                }
                else
                {
                    this._logger.Error(str);
                    strs = null;
                }
            }
            else
            {
                strs = this.Broadping();
            }
            return(strs);
        }