Re: [grpc-io] Re: Return response and stream together

2022-10-03 Thread 'Jan Tattermusch' via grpc.io

You cannot have a serverside handler that is both capable of sending a 
stream of responses AND sends a unary response at the same time - you have 
to choose one of the approaches. Since a handler that returns a stream of 
responses (using responseStream.WriteNextAsync() ) is the more general 
approach, you can use it, but you have to differentiate between the 
"normal" streaming responses and the "final" streaming response that 
concludes the stream. That is doable e.g. with having a protobuf message 
that can contain multiple different types of payload and then using the 
right kind of payload for each of the responses.

rpc StreamEvents (TestUnitRequest) returns (stream EventOrFinalResult);

(in this case the "EventOrFinalResult" message can contain either an 
"Event" or "FinalResult" message).
On Wednesday, September 14, 2022 at 9:20:05 PM UTC+2 Easwar Swaminathan 
wrote:

> Thanks Srishti. Someone with C# knowledge will take a look soon.
>
> On Wednesday, September 14, 2022 at 12:08:33 PM UTC-7 
> srishtik...@gmail.com wrote:
>
>> i am using C# here .My rpc looks like this:
>> rpc StreamEvents (TestUnitRequest) returns (stream Events);
>>  this rpc method is used to stream events and below rpc method is used 
>> to  subscribe to events ,load program api and log timestamp values and 
>> return a boolean value on successful load.
>>  rpc SendStatus(AppStatus) returns (CommandReply);
>>
>> The client sends a request to load data and stream events from the Grpc 
>> server in the following way:
>>  var reply1 = client.SendStatus(new AppStatus {});
>> ExceptionMethod(reply1);
>>
>> var result = client.StreamEvents( new TestUnitRequest 
>> { });
>>
>> I am trying to write the streamed events to file and return boolean value 
>> to the console as:
>> Console.WriteLine(reply1.IsAccepted);
>>
>> Console.WriteLine("Streaming events.");
>> StringBuilder sb6 = new StringBuilder();
>> foreach (var cmd in result.Events)
>> {
>> sb6.Append(cmd);
>> File.AppendAllText(filePath11 + 
>> "SampleTpEventlog.txt", sb6.ToString());
>> }
>> sb6.Clear();
>>
>> But the streaming is returning null value.
>> Here is the server side code for rpc method sendStatus:
>>  disposable = service.SubscribeToEvents(OnEvents);
>> try
>> {
>> var val1 = await 
>> service.LoadTestProgram(appstatus.Dir, appstatus.Tpl, appstatus.Stpl, 
>> appstatus.Soc, appstatus.Xml, appstatus.Env, true, true);
>> // Console.WriteLine(now.ToString());
>>   
>> retval = val1;
>> 
>> }
>> catch (Exception e)
>> {
>>
>>  errmsg = e.Message;
>>  
>> }
>>
>>
>>  return new CommandReply
>> {
>>IsAccepted = retval
>>   
>>   
>> };
>>
>> server side code for rpc method StreamEvents is:
>>  public override async Task StreamEvents(TestUnitRequest tur, 
>> IServerStreamWriter responseStream, ServerCallContext context)
>> {
>> await responseStream.WriteAsync(Events);
>>
>> }
>>
>> Please let me know if this is enough.Server is on remote desktop and 
>> client on local desktop.
>>
>> On Wed, Sep 14, 2022 at 11:04 AM 'Easwar Swaminathan' via grpc.io <
>> grp...@googlegroups.com> wrote:
>>
>>> Please provide more information like what language are you using, how 
>>> does your rpc definition look like, what the server does, what the client 
>>> does etc, and what you expect to see, but didnt. In the meantime, maybe 
>>> this helps: https://grpc.io/docs/languages/go/basics/.
>>> On Tuesday, September 13, 2022 at 4:11:18 PM UTC-7 srishtik...@gmail.com 
>>> wrote:
>>>
 Hi,
 I wanted to know if its possible to stream events and also return a 
 response from the same method in Grpc server call from the client.
 how do we keep on streaming data and return a response too?

 Thanks
 Srishti Kumari

>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "grpc.io" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to grpc-io+u...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/grpc-io/14610665-5324-47af-92ac-60e5d5bf53e1n%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop 

Re: [grpc-io] Re: Return response and stream together

2022-09-14 Thread 'Easwar Swaminathan' via grpc.io
Thanks Srishti. Someone with C# knowledge will take a look soon.

On Wednesday, September 14, 2022 at 12:08:33 PM UTC-7 srishtik...@gmail.com 
wrote:

> i am using C# here .My rpc looks like this:
> rpc StreamEvents (TestUnitRequest) returns (stream Events);
>  this rpc method is used to stream events and below rpc method is used to  
> subscribe to events ,load program api and log timestamp values and return a 
> boolean value on successful load.
>  rpc SendStatus(AppStatus) returns (CommandReply);
>
> The client sends a request to load data and stream events from the Grpc 
> server in the following way:
>  var reply1 = client.SendStatus(new AppStatus {});
> ExceptionMethod(reply1);
>
> var result = client.StreamEvents( new TestUnitRequest 
> { });
>
> I am trying to write the streamed events to file and return boolean value 
> to the console as:
> Console.WriteLine(reply1.IsAccepted);
>
> Console.WriteLine("Streaming events.");
> StringBuilder sb6 = new StringBuilder();
> foreach (var cmd in result.Events)
> {
> sb6.Append(cmd);
> File.AppendAllText(filePath11 + 
> "SampleTpEventlog.txt", sb6.ToString());
> }
> sb6.Clear();
>
> But the streaming is returning null value.
> Here is the server side code for rpc method sendStatus:
>  disposable = service.SubscribeToEvents(OnEvents);
> try
> {
> var val1 = await 
> service.LoadTestProgram(appstatus.Dir, appstatus.Tpl, appstatus.Stpl, 
> appstatus.Soc, appstatus.Xml, appstatus.Env, true, true);
> // Console.WriteLine(now.ToString());
>   
> retval = val1;
> 
> }
> catch (Exception e)
> {
>
>  errmsg = e.Message;
>  
> }
>
>
>  return new CommandReply
> {
>IsAccepted = retval
>   
>   
> };
>
> server side code for rpc method StreamEvents is:
>  public override async Task StreamEvents(TestUnitRequest tur, 
> IServerStreamWriter responseStream, ServerCallContext context)
> {
> await responseStream.WriteAsync(Events);
>
> }
>
> Please let me know if this is enough.Server is on remote desktop and 
> client on local desktop.
>
> On Wed, Sep 14, 2022 at 11:04 AM 'Easwar Swaminathan' via grpc.io <
> grp...@googlegroups.com> wrote:
>
>> Please provide more information like what language are you using, how 
>> does your rpc definition look like, what the server does, what the client 
>> does etc, and what you expect to see, but didnt. In the meantime, maybe 
>> this helps: https://grpc.io/docs/languages/go/basics/.
>> On Tuesday, September 13, 2022 at 4:11:18 PM UTC-7 srishtik...@gmail.com 
>> wrote:
>>
>>> Hi,
>>> I wanted to know if its possible to stream events and also return a 
>>> response from the same method in Grpc server call from the client.
>>> how do we keep on streaming data and return a response too?
>>>
>>> Thanks
>>> Srishti Kumari
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "grpc.io" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to grpc-io+u...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/grpc-io/14610665-5324-47af-92ac-60e5d5bf53e1n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/07ccb7f5-7386-42b1-bf86-f332f41e307dn%40googlegroups.com.


Re: [grpc-io] Re: Return response and stream together

2022-09-14 Thread Srishti Kumari
i am using C# here .My rpc looks like this:
rpc StreamEvents (TestUnitRequest) returns (stream Events);
 this rpc method is used to stream events and below rpc method is used to
subscribe to events ,load program api and log timestamp values and return a
boolean value on successful load.
 rpc SendStatus(AppStatus) returns (CommandReply);

The client sends a request to load data and stream events from the Grpc
server in the following way:
 var reply1 = client.SendStatus(new AppStatus {});
ExceptionMethod(reply1);

var result = client.StreamEvents( new TestUnitRequest {
});

I am trying to write the streamed events to file and return boolean value
to the console as:
Console.WriteLine(reply1.IsAccepted);

Console.WriteLine("Streaming events.");
StringBuilder sb6 = new StringBuilder();
foreach (var cmd in result.Events)
{
sb6.Append(cmd);
File.AppendAllText(filePath11 +
"SampleTpEventlog.txt", sb6.ToString());
}
sb6.Clear();

But the streaming is returning null value.
Here is the server side code for rpc method sendStatus:
 disposable = service.SubscribeToEvents(OnEvents);
try
{
var val1 = await
service.LoadTestProgram(appstatus.Dir, appstatus.Tpl, appstatus.Stpl,
appstatus.Soc, appstatus.Xml, appstatus.Env, true, true);
// Console.WriteLine(now.ToString());

retval = val1;

}
catch (Exception e)
{

 errmsg = e.Message;

}


 return new CommandReply
{
   IsAccepted = retval


};

server side code for rpc method StreamEvents is:
 public override async Task StreamEvents(TestUnitRequest tur,
IServerStreamWriter responseStream, ServerCallContext context)
{
await responseStream.WriteAsync(Events);

}

Please let me know if this is enough.Server is on remote desktop and client
on local desktop.

On Wed, Sep 14, 2022 at 11:04 AM 'Easwar Swaminathan' via grpc.io <
grpc-io@googlegroups.com> wrote:

> Please provide more information like what language are you using, how does
> your rpc definition look like, what the server does, what the client does
> etc, and what you expect to see, but didnt. In the meantime, maybe this
> helps: https://grpc.io/docs/languages/go/basics/.
> On Tuesday, September 13, 2022 at 4:11:18 PM UTC-7 srishtik...@gmail.com
> wrote:
>
>> Hi,
>> I wanted to know if its possible to stream events and also return a
>> response from the same method in Grpc server call from the client.
>> how do we keep on streaming data and return a response too?
>>
>> Thanks
>> Srishti Kumari
>>
> --
> You received this message because you are subscribed to the Google Groups "
> grpc.io" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to grpc-io+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grpc-io/14610665-5324-47af-92ac-60e5d5bf53e1n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CAACOWgBizyjMfMAW_F%3D40agVotYex_jAM0ODBJKFx-KV4R585g%40mail.gmail.com.