简体   繁体   English

如何使用Winform中的SignalR Hub将服务器上数据网格中存储的详细信息发送到客户端

[英]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, 我已经使用信号器将每一个客户端数据存储在datagrid中的服务器上(每当客户端连接服务器上更新的所有客户端的详细信息(例如ipaddress,名称等)...)时,我想将该datagrid详细信息发送给所有客户端,条件是每当新客户端连接到服务器,那么包括当前客户端在内的所有客户端都必须获取更新的列表...。这基本上是我到目前为止所做的代码,

  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.. 并在datagird中的服务器上显示此列表...我必须将此列表发送给所有客户端...请帮助我...谢谢......或者还有其他方法还是我做错了请告诉我..

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. 它有一个示例,说明您将如何在Winforms客户端上执行操作。

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

and the source code for the winforms client: 以及winforms客户端的源代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用winform将Signalr客户端连接到不同计算机上的Signalr服务器 - how to connect Signalr client to Signalr server on Different computers using winform 如何使用Winform Signalr将数据从客户端传递到服务器 - How to pass data from client to server using winform signalr 如何编写两个具有服务器方法的集线器,它们在while循环中运行并将数据发送到SignalR客户端 - how to write two hub which has server method runs in while loop and send data to SignalR client 如何使用SignalR将文本框中的文本从客户端发送到集线器 - How to send text from textbox with SignalR from client to hub 如何从websocket-sharp客户端发送文件到SignalR集线器? - How to Send File to SignalR hub From websocket-sharp Client? 如何使用SignalR将消息发送到特定客户端 - How to send message to a particular client using SignalR 如何将数据发送回 SignalR Hub - How to send data back into SignalR Hub 如何实现 ILogger 将消息发送到 SignalR 集线器? - How to implement an ILogger to send messages to a SignalR Hub? 使用信号器和 Java 客户端将 json 对象发送到 .net 服务器 - Send a json object to .net server using signalr and Java client 如何使用 SignalR 集线器将消息从服​​务器发送到客户端 - How do I send messages from server to client using SignalR Hubs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM