Пример #1
0
 public override void Write(OkBuffer p_source, long p_byteCount)
 {
     _currentLength += p_byteCount;
     // 回调进度
     _progressListener?.Invoke(p_byteCount, _currentLength, _totalLength);
     base.Write(p_source, p_byteCount);
 }
Пример #2
0
            public override void Write(OkBuffer p0, long p1)
            {
                base.Write(p0, p1);

                bytesWritten += p1;
                _parent?._listener.OnProgress(bytesWritten, _parent.ContentLength());
            }
Пример #3
0
        void IWebSocketListener.OnPong(OkBuffer buffer)
        {
            var handler = Pong;

            if (handler != null)
            {
                handler(sender, new PongEventArgs(buffer));
            }
        }
Пример #4
0
        void IWebSocketListener.OnPong(OkBuffer buffer)
        {
            var handler = Pong;

            if (handler != null)
            {
                handler(buffer);
            }
        }
            public override void Write(OkBuffer p0, long p1)
            {
                try
                {
                    base.Write(p0, p1);

                    bytesWritten += p1;
                    _parent?._listener.OnProgress(bytesWritten, _parent.ContentLength());
                }
                catch (Java.IO.IOException ex)
                {
                    _parent?._listener?.OnError(_parent._tag, ex.ToString());
                }
            }
Пример #6
0
        private void StartMessages(IWebSocket webSocket)
        {
            // we want to ping every 2 seconds
            new Timer(state =>
            {
                var buffer = new OkBuffer();
                buffer.WriteString("Ping!", Charset.DefaultCharset());
                webSocket.SendPing(buffer);
            }, null, TimeSpan.Zero, TimeSpan.FromSeconds(2));

            // we want to send a message every 5 seconds
            new Timer(state =>
            {
                var body = RequestBody.Create(WebSocket.Text, "Hello World!");
                webSocket.SendMessage(body);
            }, null, TimeSpan.Zero, TimeSpan.FromSeconds(3));
        }
        public long Read(OkBuffer sink, long byteCount)
        {
            if (bytesLeft == -1L)
            {
                throw new ArgumentException("closed");
            }
            if (bytesLeft == 0L)
            {
                return(-1L);
            }
            if (byteCount > int.MaxValue)
            {
                byteCount = int.MaxValue;
            }
            if (byteCount > bytesLeft)
            {
                byteCount = bytesLeft;
            }

            // Random is most efficient when computing 32 bits of randomness. Start with that.
            int ints = (int)(byteCount / 4);

            for (int i = 0; i < ints; i++)
            {
                sink.WriteInt(random.Next());
            }

            // If we need 1, 2, or 3 bytes more, keep going. We'll discard 24, 16 or 8 random bits!
            int bytes = (int)(byteCount - ints * 4);

            if (bytes > 0)
            {
                int bits = random.Next();
                for (int i = 0; i < bytes; i++)
                {
                    sink.WriteByte(bits & 0xff);
                    bits >>= 8;
                }
            }

            bytesLeft -= byteCount;
            return(byteCount);
        }