C# SSE Client - OnMessage not firing

Hello there, I am losing my mind on this. Can someone tell me what I am doing wrong. It is supposed to be so simple…I can connect, get heartbeats but I do not get any messages from the server. I have tried NotifyChannel, NotifyAll, etc… I have my service up and running. I start a console app and connect and post and get a response but no message. I also open a browser and do a Get so it would also send messages to all subscribers but nothing. Also, why can’t I have two console app connecting to the host. When I start a second one, it fails to connect. And why do we have to call client.connect if we already called client.start?

Here is the whole thing. Please, someone, save my week-end! Thanks in advance.

Console App

class Program
{
        static void Main(string[] args)
        {          
            ServerEventConnect connectMsg = null;
            var msgs = new List<ServerEventMessage>();
            var commands = new List<ServerEventMessage>();
            var errors = new List<Exception>();

            var client = new ServerEventsClient("http://192.168.0.27:8085", "realtime"){
                OnConnect = e => connectMsg = e,
                OnCommand = commands.Add,
                OnMessage = ShowMessage,
                OnException = errors.Add,
            }.Start();

            client.Connect();
            Console.WriteLine(connectMsg.Data);           
            var req = new SseRequest()
            {
                Channel = client.Channels.FirstOrDefault(),
                StartTime = DateTime.Now.AddDays(-1),
                EndTime = DateTime.Now,
                RealTime = true,
                Interval = 60000
            };
            try
            {
                var resp=client.ServiceClient.Post(req);                
                Console.WriteLine(resp.Result);                
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadKey();            
            client.Stop();
        }

        private static void ShowMessage(ServerEventMessage msg)
        {
            Console.WriteLine($"Received message : {msg.Data}");
        }
    }

Server

public class CoreService:Service
{
        public IServerEvents Sse { get; set; }        
        public TestResponse Post(SseRequest request)
        {            
            Sse.NotifyAll("","Message for all from POST.");
            return  new TestResponse(){Result=$"Hello {request.Channel}"};
        }
        public TestResponse Get(SseRequest request)
        {
            Sse.NotifyAll("","Message for all from GET.");
            return  new TestResponse(){Result=$"Hello {request.Channel}"};
        }
}

Alright. I need to put something (even though I do not have any handlers?!) into the selector…
Problem solved again.

1 Like