Ejemplo n.º 1
0
    public async Task ServerMethodThatReturnsCustomTypeWithInnerStream()
    {
        StreamContainingClass result = await this.clientRpc.InvokeAsync <StreamContainingClass>(nameof(Server.ServerMethodThatReturnsCustomTypeWithStream));

        var returnedContent = await new StreamReader(result.InnerStream).ReadToEndAsync();

        Assert.Equal("More streamed bits!", returnedContent);

        result.InnerStream.Dispose();
    }
Ejemplo n.º 2
0
        public StreamContainingClass ServerMethodThatReturnsCustomTypeWithStream()
        {
            var streamPair = FullDuplexStream.CreatePair();
            var stream     = new StreamContainingClass(streamPair.Item2);

            var bytes = Encoding.UTF8.GetBytes("More streamed bits!");

            streamPair.Item1.Write(bytes, 0, bytes.Length);
            streamPair.Item1.Flush();

            // Dispose of the stream to notify the receiving side that no more content will be sent
            streamPair.Item1.Dispose();

            return(stream);
        }
Ejemplo n.º 3
0
        public async Task <int> AcceptStreamArgInFirstParam(StreamContainingClass allArgs)
        {
            Requires.NotNull(allArgs.InnerStream, nameof(allArgs.InnerStream));

            int totalBytesRead = 0;

            byte[] buffer = new byte[128];
            while (true)
            {
                int bytesRead = await allArgs.InnerStream.ReadAsync(buffer, 0, buffer.Length);

                if (bytesRead == 0)
                {
                    break;
                }

                totalBytesRead += bytesRead;
            }

            return(totalBytesRead);
        }