Exemple #1
0
        /// <summary>
        /// Will send count bytes from a byte array, starting from offset.
        /// </summary>
        public void Send(byte[] data, ulong offset, ulong count)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data must not be null!");
            }
            if (offset + count > (ulong)data.Length)
            {
                throw new ArgumentOutOfRangeException("offset + count >= data.Length");
            }

            WebSocketFrame frame = new WebSocketFrame(this.WebSocket, WebSocketFrameTypes.Binary, data, offset, count, true, true);

            if (frame.Data != null && frame.Data.Length > this.MaxFragmentSize)
            {
                WebSocketFrame[] additionalFrames = frame.Fragment(this.MaxFragmentSize);

                lock (SendLock)
                {
                    Send(frame);

                    if (additionalFrames != null)
                    {
                        for (int i = 0; i < additionalFrames.Length; ++i)
                        {
                            Send(additionalFrames[i]);
                        }
                    }
                }
            }
            else
            {
                Send(frame);
            }
        }
Exemple #2
0
        /// <summary>
        /// It will send the given message to the server in one frame.
        /// </summary>
        public void Send(string message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message must not be null!");
            }

            int count = System.Text.Encoding.UTF8.GetByteCount(message);

            byte[] data = BufferPool.Get(count, true);
            System.Text.Encoding.UTF8.GetBytes(message, 0, message.Length, data, 0);

            var frame = new WebSocketFrame(this.WebSocket, WebSocketFrameTypes.Text, data, 0, (ulong)count, true, true);

            if (frame.Data != null && frame.Data.Length > this.MaxFragmentSize)
            {
                WebSocketFrame[] additionalFrames = frame.Fragment(this.MaxFragmentSize);

                Send(frame);
                if (additionalFrames != null)
                {
                    for (int i = 0; i < additionalFrames.Length; ++i)
                    {
                        Send(additionalFrames[i]);
                    }
                }
            }
            else
            {
                Send(frame);
            }

            BufferPool.Release(data);
        }
Exemple #3
0
        /// <summary>
        /// It will send the given data to the server in one frame.
        /// </summary>
        public void Send(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data must not be null!");
            }

            WebSocketFrame frame = new WebSocketFrame(this.WebSocket, WebSocketFrameTypes.Binary, data);

            if (frame.Data != null && frame.Data.Length > this.MaxFragmentSize)
            {
                WebSocketFrame[] additionalFrames = frame.Fragment(this.MaxFragmentSize);

                lock (SendLock)
                {
                    Send(frame);
                    if (additionalFrames != null)
                    {
                        for (int i = 0; i < additionalFrames.Length; ++i)
                        {
                            Send(additionalFrames[i]);
                        }
                    }
                }
            }
            else
            {
                Send(frame);
            }
        }
        /// <summary>
        /// It will send the given data to the server in one frame.
        /// </summary>
        public void Send(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data must not be null!");
            }

            WebSocketFrame frame = new WebSocketFrame(this.WebSocket, WebSocketFrameTypes.Binary, data);

            if (this.WebSocket.EnableAdditionalLogging)
            {
                HTTPManager.Logger.Verbose("WebSocketResponse", "Send - data length: " + data.Length, this.Context);
            }

            if (frame.Data != null && frame.Data.Length > this.MaxFragmentSize)
            {
                WebSocketFrame[] additionalFrames = frame.Fragment(this.MaxFragmentSize);

                Send(frame);
                if (additionalFrames != null)
                {
                    for (int i = 0; i < additionalFrames.Length; ++i)
                    {
                        Send(additionalFrames[i]);
                    }
                }
            }
            else
            {
                Send(frame);
            }
        }