protected override async Task SendAsync(WampMessage <object> message)
 {
     using (WebSocketMessageWriteStream stream =
                mWebsocket.CreateMessageWriter(WebSocketMessageType.Binary))
     {
         byte[] raw = mBinding.Format(message);
         await stream.WriteAsync(raw, 0, raw.Length).ConfigureAwait(false);
     }
 }
Example #2
0
        /// <summary>
        /// Sends a byte array to the client
        /// </summary>
        /// <param name="message">The byte array to send</param>
        /// <returns></returns>
        public async Task SendMessage(byte[] message)
        {
            if (!Socket.IsConnected)
            {
                return;
            }

            using (WebSocketMessageWriteStream messageWriter = Socket.CreateMessageWriter(WebSocketMessageType.Binary))
                await messageWriter.WriteAsync(message, 0, message.Length);
        }
        public override async Task CloseAsync()
        {
            if (_isClosed)
            {
                return;
            }

            _isClosed = true;
            await _deflate.FlushAsync().ConfigureAwait(false);

            SafeEnd.Dispose(_deflate); // TODO DeflateStream cant async flush buffer so this will cause sync Write call and blocks one thread from pool
            await _inner.WriteAsync(BFINAL, 0, 1).ConfigureAwait(false);

            await _inner.CloseAsync().ConfigureAwait(false);
        }