0

I wanna send a server sent event back to a client each time when a new event is triggered.

But inside of my callback I call a static method named commonEventBuffer.sendIncommingEvent() and I am passing the text of the message (which should be sent back to the client, as also the response object) but within that method I get an excpetion at the _resp.write() call.

As an expection message I am getting "Object reference not set to an instance of an object.

So what do I wrong?

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace HomeScadaWebApp
{
    /// <summary>
    /// Summary description for incommingEventHandler
    /// </summary>
    public class incommingEventHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            commonEventBuffer._storedResponse = context.Response;
            getNotification.myHandler += CB;
        }

        private void CB(object sender, EventArgs e)
        {
            string s = commonAESStuff.getEventChanges();
            commonEventBuffer.sendIncommingEvent(s,commonEventBuffer._storedResponse);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}


//class commonEventBuffer.cs (is an additional file!!)


public class commonEventBuffer
{
    public  static HttpResponse _storedResponse;

    public static void addEvent(String s)
    {
        commonAESStuff.addEventChange(s);
    }

    public static void sendIncommingEvent(string s,HttpResponse _resp)
    {
        if (_resp != null && s != null)
        {
            try
            {
                _resp.ContentType = "text/event-stream";
                _resp.Write("data:" + s.ToString() + "\n\n");
                _resp.Flush();
            }
            catch (Exception ex)
            {

            }
        }
    }
}
d s
  • 237
  • 1
  • 2
  • 11

0 Answers0