SignalR Hubs Windows Form - newbie -


i've built hosted (owin) windows form hub, not acting proxy client, want have small windows form show other clients connect.

the bit im struggling host client "listening" , how log connected machines. want write out message textbox

so here have done far, im running client\hub on same form.

public partial class form1 : form {     private idisposable signalr { get; set; }     private hubconnection hubconnection;     private ihubproxy chat;     const string url = "http://localhost:8080";      public form1()     {         initializecomponent();     }      private void form1_load(object sender, eventargs e)     {         task.run(() => startserver());         //task.run(() => registerserverconnection());     }      private void startserver()     {         try         {             signalr = webapp.start(url);         }         catch (targetinvocationexception)         {          }         this.invoke((action) (() => richtextbox1.appendtext("server running on " + url)));       }      private async void registerserverconnection()     {         hubconnection = new hubconnection(url);         hubconnection.groupstoken = "rooma";          chat = hubconnection.createhubproxy("chat");          int timeout = 10000;         var task = hubconnection.start();         if (await task.whenany(task, task.delay(timeout)) == task)         {             // await chat.invoke<connectionmodel>("clientconnected", connectionmodel);             this.invoke((action)(() => richtextbox1.text+="connected"));             //  this.hide();         }         else         {             this.invoke((action)(() => richtextbox1.appendtext("unable connect.")));         }           chat.invoke<chatmessage>("send", new chatmessage() { msg = "host running", groupname = "host" });     }      private void btngo_click(object sender, eventargs e)     {         registerserverconnection();     }    } 

[hubname("chat")]     public class chathub : hub     {         public void sendmessage(string message)         {             var msg = string.format(                 "{0}: {1}", context.connectionid, message);             clients.all.newmessage(msg);         }          public override task onconnected()         {             return base.onconnected();         }            public void send(chatmessage message)         {             // call addmessage method on clients                         clients.all.addmessage(message.msg);             clients.group(message.groupname).newmessage("group message " + message.msg);         } } 

this did, may try:

  1. create arraylist in form1 following structure: connectionid, loginid, serversideencryptedloginpw.

  2. during onconnected (when client connected before login), add element arraylist (connectionid, empty, empty).

  3. add login function in hub. after client call function, update loginid , encrypted loginpw in arraylist particular connectionid. (check password in database, if have one)

  4. during ondisconnected, remove element in arraylist particular connectionid.

  5. for other functions in hub, clients must provide loginid , encrypted password.

  6. in windows form, shows values in arraylist when changes, e.g. no. of clients connected, no. of clients logined, list of clients' loginid, etc.

something that!


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -