Ejemplo n.º 1
0
        /// <summary>
        /// Sends a binary <paramref name="data"/> asynchronously using the WebSocket connection.
        /// </summary>
        /// <remarks>
        /// This method doesn't wait for the send to be complete.
        /// </remarks>
        /// <param name="data">
        /// An array of <see cref="byte"/> that represents the binary data to send.
        /// </param>
        /// An Action&lt;bool&gt; delegate that references the method(s) called when the send is
        /// complete. A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
        /// complete successfully; otherwise, <c>false</c>.
        public Task SendAsync(byte[] data)
        {
            var msg = _readyState.CheckIfOpen() ?? data.CheckIfValidSendData();

            if (msg != null)
            {
                throw new Exception(msg);
            }

            return(sendAsync(Opcode.Binary, _memoryStreamFactory.CreateNew(data)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a binary <paramref name="data"/> asynchronously using the WebSocket connection.
        /// </summary>
        /// <remarks>
        /// This method doesn't wait for the send to be complete.
        /// </remarks>
        /// <param name="data">
        /// An array of <see cref="byte"/> that represents the binary data to send.
        /// </param>
        /// <param name="completed">
        /// An Action&lt;bool&gt; delegate that references the method(s) called when the send is
        /// complete. A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
        /// complete successfully; otherwise, <c>false</c>.
        /// </param>
        public void SendAsync(byte[] data, Action <bool> completed)
        {
            var msg = _readyState.CheckIfOpen() ?? data.CheckIfValidSendData();

            if (msg != null)
            {
                error(msg);

                return;
            }

            sendAsync(Opcode.Binary, new MemoryStream(data), completed);
        }
        /// <summary>
        /// Sends a binary <paramref name="data"/> asynchronously using the WebSocket connection.
        /// </summary>
        /// <remarks>
        /// This method doesn't wait for the send to be complete.
        /// </remarks>
        /// <param name="data">
        /// An array of <see cref="byte"/> that represents the binary data to send.
        /// </param>
        /// An Action&lt;bool&gt; delegate that references the method(s) called when the send is
        /// complete. A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
        /// complete successfully; otherwise, <c>false</c>.
        public Task SendAsync(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            var msg = _readyState.CheckIfOpen();

            if (msg != null)
            {
                throw new Exception(msg);
            }

            return(sendAsync(Opcode.Binary, new MemoryStream(data)));
        }