Send() публичный Метод

Send the given text over the specified protocol.
public Send ( byte bytes, int offset, int length, AsyncContinuation asyncContinuation ) : void
bytes byte Bytes to be sent.
offset int Offset in buffer.
length int Number of bytes to send.
asyncContinuation AsyncContinuation The asynchronous continuation.
Результат void
Пример #1
0
        private void ChunkedSend(NetworkSender sender, byte[] buffer, AsyncContinuation continuation)
        {
            int tosend = buffer.Length;
            int pos = 0;

            AsyncContinuation sendNextChunk = null;

            sendNextChunk = ex =>
                {
                    if (ex != null)
                    {
                        continuation(ex);
                        return;
                    }

                    if (tosend <= 0)
                    {
                        continuation(null);
                        return;
                    }

                    int chunksize = tosend;
                    if (chunksize > this.MaxMessageSize)
                    {
                        if (this.OnOverflow == NetworkTargetOverflowAction.Discard)
                        {
                            continuation(null);
                            return;
                        }

                        if (this.OnOverflow == NetworkTargetOverflowAction.Error)
                        {
                            continuation(new OverflowException("Attempted to send a message larger than MaxMessageSize (" + this.MaxMessageSize + "). Actual size was: " + buffer.Length + ". Adjust OnOverflow and MaxMessageSize parameters accordingly."));
                            return;
                        }

                        chunksize = this.MaxMessageSize;
                    }

                    int pos0 = pos;
                    tosend -= chunksize;
                    pos += chunksize;

                    sender.Send(buffer, pos0, chunksize, sendNextChunk);
                };

            sendNextChunk(null);
        }
Пример #2
0
        private void ChunkedSend(NetworkSender sender, byte[] buffer)
        {
            int tosend = buffer.Length;
            int pos = 0;

            while (tosend > 0)
            {
                int chunksize = tosend;
                if (chunksize > MaxMessageSize)
                {
                    if (OnOverflow == OverflowAction.Discard)
                        return;

                    if (OnOverflow == OverflowAction.Error)
                        throw new OverflowException("Attempted to send a message larger than MaxMessageSize(" + MaxMessageSize + "). Actual size was: " + buffer.Length + ". Adjust OnOverflow and MaxMessageSize parameters accordingly.");

                    chunksize = MaxMessageSize;
                }
                sender.Send(buffer, pos, chunksize);
                tosend -= chunksize;
                pos += chunksize;
            }
        }