Here is the server code

class Program
    {
        static void Main(string[] args)
        {
            Server server = new Server
            {
                Services = { Logger.Logger.BindService(new LoggerImp()) },
                Ports = { new ServerPort("192.168.1.223", 50051, 
ServerCredentials.Insecure) }
            };
            server.Start();


            Console.WriteLine("Greeter server listening on port " + 50051);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();


            server.ShutdownAsync().Wait();
        }
    }


class LoggerImp : Logger.Logger.LoggerBase
    {
        private HashSet<IServerStreamWriter<LogMessage>> listeners = new 
HashSet<IServerStreamWriter<LogMessage>>();


        public override Task ListenForMessages(LogListener request, 
IServerStreamWriter<LogMessage> responseStream, ServerCallContext context)
        {
            return base.ListenForMessages(request, responseStream, context);
        }


        public override async Task SendLogMessages(IAsyncStreamReader<
LogMessage> requestStream, IServerStreamWriter<LogMessage> responseStream, 
ServerCallContext context)
        {
            listeners.Add(responseStream);


            while (await requestStream.MoveNext())
            {
                var current = requestStream.Current;
                if (current.ClientType == 1)
                {
                    listeners.Add(responseStream);
                }


                foreach (IServerStreamWriter<LogMessage> listener in 
listeners)
                {
                    try
                    {
                        await listener.WriteAsync(current);
                    }
                    catch (Exception)
                    {
                        //client stream no longer exists so remove it from 
list of active streams
                        listeners.Remove(listener);
                    }


                }
            }
        }
    }

The server will throw an error on the line 

await listener.WriteAsync(current); 

if the stream is no longer active (ie. I stopped the wpf app, started it 
again and the server tries to send a message to a stream that does not 
exist) I expected this but when this happens this also throws that 
RpcException in the Wpf app which I didn't think would happen because I am 
catching the exception on the server when I try to write to the stream but 
it still seems to propagate back to the client.

What I am trying to do is keep a list of all streams of a certain client 
type, these streams then see any message that comes in from any client.

On Wednesday, October 3, 2018 at 4:28:10 PM UTC-4, Benjamin Krämer wrote:
>
> Looks to my like the server side threw an exception. Can you also paste 
> the server side?
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/435965fc-c198-4851-b1be-65294f5f9540%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to