服务器使用WriteAsync方法时具有“响应流已完成”

时间:2019-09-11 09:07:44

标签: c# grpc

我得到“响应流已经完成。”当服务器使用pi-stream调用WriteAsync()方法时,只有当我使用Thread.sleep时,客户端有时才能在睡眠时间内获取流。但是我知道那不是解决方案,所以plz告诉我该怎么办!

我使用.net core 2.2和vs community 2019 16.2.3

                proto:
                rpc CppyFile(stream Chunk)returns(stream Back){}

                message Chunk{
                bytes Content=1;
                string FileName=2;
                string Flag=3;
                }

                message Back{
                bytes Content=1;
                UploadStatus statue=2;
                string Flag=3;
                }


                Server:
                await responseStream.WriteAsync(new Back
                            {
                                Content = ByteString.FromStream(stream),
                                Flag = fname,
                                Statue = new UploadStatus
                                {
                                    Message = "2",
                                    Code = UploadStatusCode.Unknown
                                }
                            });


                client:

                using (var call = client.CppyFile())
            {

                try
                {
                    await call.RequestStream.WriteAsync(chunk);
                    Console.WriteLine("Sending");

                        //################################################################################## here's Problem

                        await call.RequestStream.CompleteAsync();
                    //Thread.Sleep(8 * 1000);
                        //##################################################################################

                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }

                 var responseReaderTask = Task.Run(async () =>
                { 
                    while (await call.ResponseStream.MoveNext())
                    {
                        var note = call.ResponseStream.Current;    
                                        //get sending from server
                                        ......

这是详细信息错误。

System.InvalidOperationException:响应流已经完成。    位于Grpc.Core.Internal.AsyncCallServer 2.CheckSendAllowedOrEarlyResult() in T:\src\github\grpc\src\csharp\Grpc.Core\Internal\AsyncCallServer.cs:line 195 at Grpc.Core.Internal.AsyncCallBase 2.SendMessageInternalAsync(TWrite msg,WriteFlags writeFlags)在T:\ src \ github \ grpc \ src \ csharp \ Grpc.Core \ Internal \ AsyncCallBase.cs:line 124 < / p>

0 个答案:

没有答案