gpt4 book ai didi

带有远程客户端的 WinForm 中的 SignalR 聊天应用程序

转载 作者:行者123 更新时间:2023-12-02 07:01:12 28 4
gpt4 key购买 nike

我是 signalR 的新手,我已经尝试从 github 等不同的网站学习

但是我找不到解决问题的办法....现在我很困惑...

我的问题是:

我在 Winform 中使用 Web 服务和中央数据库开发了一个聊天应用程序,它在不同国家和一个组织的不同分支机构中运行良好。

但我想将该聊天应用程序转换为 SignalR 以提高效率,但我不明白如何在 SignalR 中进行。因为 Web 上的所有 SignalR 教程都在一个解决方案中。

像 Web 、控制台或 WinRT 一样相互通信,但它们在一个解决方案中,但在我的场景中,我无法将服务或网页放入 WinForm 应用程序中。

请以这种方式帮助我。

最佳答案

您需要做的是为 .NET 客户端使用 SignalR。假设您使用的是 Visual Studio,则使用 NuGet 将其引入您的项目。

您通常需要导入以下内容:

 using Microsoft.AspNet.SignalR.Client;
using Microsoft.AspNet.SignalR.Client.Hubs;

假设您正在学习网络上的大部分教程,您可能需要以下内容进行连接:

 public IHubProxy Proxy { get; set; }
public HubConnection Connection { get; set; }

您还需要像这样设置连接:

 public string Host = "http://YourSignalRChatAppLocationOnAzureOrLocally.cloudapp.net/"; 
Connection = new HubConnection(Host);
//Assuming your SignalR hub is also called ChatHub (If you followed most tutorials it will be)
Proxy = Connection.CreateHubProxy("ChatHub");

这部分需要在异步函数中:

 //If you are passing an object back and fourth otherwise String is fine
Proxy.On<ChatMessage>("Send", hello => OnSendData("Recieved send " + hello.Username + " " + hello.Content));
await Connection.Start();

更多资料来自下面的链接,这个人在控制台应用程序、WPF 应用程序和 Web 客户端上运行它,因此您可以看到不同之处。

Standard tutorial on how to make the web server.

SIGNALR MESSAGING WITH CONSOLE SERVER AND CLIENT, WEB CLIENT, WPF CLIENT

关于带有远程客户端的 WinForm 中的 SignalR 聊天应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20476404/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com