简体   繁体   中英

How to send details stored in datagrid on server to client using SignalR Hub in winform

i have stored some client data on server in datagrid using signalr (whenever client connects details of all clients updated on server like ipaddress, name etc)... so i want to send that datagrid details to all clients and the condition is whenever new clients connect to server then all client including current client must get updated list ....here is my code basically what i have done till now,

  public override Task OnConnected()
    {
        object ipaddress;
        var a=Context.QueryString["name"];
        var b= Context.QueryString["AnotherValue"];
        if (Context.Request.Environment.TryGetValue("server.RemoteIpAddress", out ipaddress))
        {
            //ipcollections = new List<string[]>();

            userhandler.ipcol.Add(new string[] {  ipaddress.ToString(), a, b });
            Program.MainForm.writetodatagrid(userhandler.ipcol);
        }

        Program.MainForm.WriteToConsole("Client connected: " + Context.ConnectionId );
        return base.OnConnected();

    }

and showing this list on server itself in datagird...i have to send this list to all clients...please help me...thank you....or is there any other way or am i doing things wrong please tell me..

On the server you would have a Hub and a method on the Hub to broadcast.

    public class MyHub : Hub 
    { 
        public void Send(string ipaddress, string name) 
        { 
            Clients.All.addMessage(ipaddress, name); 
        }
    }

Take a look at the following post. It has a an example of what you would do on your winforms client.

https://code.msdn.microsoft.com/windowsdesktop/Using-SignalR-in-WinForms-f1ec847b#content

and the source code for the winforms client:

https://code.msdn.microsoft.com/windowsdesktop/Using-SignalR-in-WinForms-f1ec847b/sourcecode?fileId=119892&pathId=583880341

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM