[英]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.