SignalR selfhost server does not working

298 views Asked by At

We've developed SignalR selfhost server in "c#.net as window services" and accessed by mobile application as client. We've developed with help of this link http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host.

This window services is running fine and after couple of days, mobile server could not response to the mobile client. We didn't know the reason why server is not working after couple of days.But window service is running successfully only didn't response to mobile client.

Also we tried restart service for every 6 hours but still we have no solution. Our code on server side is Startup class

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR(new HubConfiguration() { EnableJSONP = true });
    }
}

Service class

public partial class MobileService : ServiceBase
{
    //SignalR
    private IDisposable signalR { get; set; }
    public string App_ServerURL = null;   
    public MobileHub obj_HubCMobileServer = new MobileHub();     
    public MobileService()
    {
        InitializeComponent();

    }

    protected override void OnStart(string[] args)
    {
        try
        {
                    App_ServerURL = "http://192.168.1.4:8888";
                    obj_HubCMobileServer.Init();
                    Task.Run(() => StartServer());                   
        }
        catch (Exception ex)
        {
            MobileService.Instance.server_Log(ex.Message + ex.StackTrace);
        }
    }

    private void StartServer()
    {
        try
        {
           // server_Log("SignalR server init  " + App_ServerURL);
            signalR = WebApp.Start(App_ServerURL);                
            server_journal("SignalR server started at  " + App_ServerURL);
            GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(50);                               
        }
        catch (Exception ex)
        {                
            server_Log(ex.Message + ex.StackTrace);
            return;
        }

    }

HUB class

public class MobileHub : Hub
{
    IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MobileHub>();

    static readonly object thisLock = new object();
    System.Timers.Timer timer = new System.Timers.Timer();
    public void Init()
    {
        try
        {                
            timer.Enabled = true;
            timer.Start();
            timer.Interval = 1000;
            timer.Elapsed += timer_Elapsed;                 
        }
        catch (Exception ex)
        {
            MobileService.Instance.server_Log(ex.Message + ex.StackTrace);
        }
    }  
    .....
    .....
    .....
    public override Task OnConnected()
    {
                  return base.OnConnected();
    }

    public override Task OnDisconnected(bool stopCalled)
    {           
        return base.OnDisconnected(stopCalled);
    }
    public override Task OnReconnected()
    {

        return (base.OnReconnected());
    }

}

Anyone could you give solution or is there anyway restart mobile SignalR selfhost server for every 12 hours?

0

There are 0 answers