c# - Signal R - Handling a disconnect outside of a hub -


i trying accomplish sending data client methods controller method returns response when instance client disconnected.

controller currently..

 public void somemethod(){     ihubcontext hubcontext = globalhost.connectionmanager.gethubcontext<myhub>();      while(true){          hubcontext.clients.all.addnamevalue(name,value);     }  } 

what like..

 bool someproperty = false  public string somemethod(){     ihubcontext hubcontext = globalhost.connectionmanager.gethubcontext<myhub>();      while(true & (someproperty == false)){          hubcontext.clients.all.addnamevalue(name,value);     }     return "done";  } 

since know client disconnects hub overrided method..

hub

 public override task ondisconnected(bool stopcalled = true)     {         console.writeline("hub disconnected: {0}\n", context.connectionid);         return (base.ondisconnected(stopcalled));     } 

is there way outside hub keep track of controller instance can done?

public override task ondisconnected(bool stopcalled = true)     {         someclass.someproperty = true;         console.writeline("hub ondisconnected {0}\n", context.connectionid);         return (base.ondisconnected(stopcalled));     } 

we seek ability open connection using signal r when want stream data , forth, ability know when client disconnects client can continue doing things.

if create hub uses singleton class keep track of clients, if need can store of connected clients, able reconnect when server comes online. there no disconnect event on client, reconnected event. hard determine if server has been disconnected or not. way work around subscribe connection.closed event. me make 1 attempt reconnect, fails, notify user , exit application. info on singleton method of keeping track clients developed mine link: http://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr

       tchubproxy(hubconnection hubconnection, streamwriter writer)     {         mhubconn = hubconnection;         mihubproxy = hubconnection.createhubproxy("centralhub");         mwriter = writer;         mwriter.autoflush = true;          try         {             mhubconn.tracelevel = tracelevels.all;             mhubconn.tracewriter = mwriter;             mhubconn.closed += mhubconnonclosed;             mhubconn.start().wait();             logevent(datetime.now, "info", "client connected");             mihubproxy.on<list<user>>("updatefmds", getuserfmds);             connected = true;         }         catch (exception e)         {             if (showmessage)             {                 messagebox.show(                     "there no connection server, application close, if issue persists check network connection or contact support.",                     "connection error", messageboxbuttons.ok, messageboxicon.error);                 showmessage = false;             }              connected = false;             showmessage = false;         }     }   public void mhubconnonclosed()     {         logevent(datetime.now, "info", "client connection communication hub, attempting redirect.");         try         {             mhubconn = new hubconnection(connectionstring);             mhubconn.tracelevel = tracelevels.all;             mhubconn.tracewriter = mwriter;             mihubproxy = mhubconn.createhubproxy("centralhub");             mhubconn.start().wait();             logevent(datetime.now, "info", "reconnection successful.");             mihubproxy.on<list<user>>("updatefmds", getuserfmds);         }         catch (exception e)         {             logevent(datetime.now, "error", "reconnection attempt failed.", e.stacktrace, e.message);             if (showmessage)             {                 messagebox.show(                     "there no connection server, application close, if issue persists check network connection or contact support.",                     "connection error", messageboxbuttons.ok, messageboxicon.error);                 showmessage = false;             }             connected = false;         }     } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -