Esempio n. 1
0
        /// <summary>
        /// Sends a frame to the server.
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async ValueTask SendAsync(StompFrame frame, CancellationToken cancellationToken)
        {
            if (socket.Connected == false)
            {
                throw new InvalidOperationException("Socket is closed.");
            }

            // write frame to array buffer
            var b = new ArrayBufferWriter <byte>(512);

            protocol.Write(b, frame);
            await socket.SendAsync(b.WrittenMemory, SocketFlags.None, cancellationToken);
        }
        /// <summary>
        /// Sends a frame to the server.
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override ValueTask SendAsync(StompFrame frame, CancellationToken cancellationToken)
        {
            if (socket.State != WebSocketState.Open)
            {
                throw new InvalidOperationException("Web socket is closed.");
            }

            // write frame to array buffer
            var b = new ArrayBufferWriter <byte>(512);

            protocol.Write(b, frame);
            return(socket.SendAsync(b.WrittenMemory, WebSocketMessageType.Binary, true, cancellationToken));
        }