![](/img/trans.png)
[英]SignalR Client error when trying to connect to server with connection.Start()
[英]Error when I am trying to establishing a client and server connection using SignalR
我正在嘗試使用SignalR創建服務器客戶端通信。 我設法在本地執行該通信。 我的服務器端代碼如下:
class Program
{
static private IDisposable SignalR { get; set; }
const string ServerURI = "http://localhost:1234";
private static IHubProxy HubProxy { get; set; }
private static HubConnection Connection { get; set; }
static void Main(string[] args)
{
SignalR = WebApp.Start(ServerURI);
Console.WriteLine("Server running at " + ServerURI);
Connection = new HubConnection(ServerURI);
HubProxy = Connection.CreateHubProxy("MyHub");
HubProxy.On<string, string>("SendMessage", (name, message) => Console.WriteLine(name + ":" + message));
Connection.Start().Wait();
string messageToSentToClients;
do
{
Console.WriteLine("Type someting to send to clients and press enter");
messageToSentToClients = Console.ReadLine();
HubProxy.Invoke("Send", "Server", messageToSentToClients);
} while (messageToSentToClients != "exit");
}
}
public class MyHub : Hub
{
public void Send(string name, string message) { Clients.All.sendMessage(name, message); }
}
class Startup
{
public void Configuration(IAppBuilder app) { app.MapSignalR(); }
}
該代碼正在與位於同一機器中的客戶端一起使用。 我想與同一局域網中的客戶端一起工作,但不在同一台計算機中。 為了能夠與不在同一台計算機上的客戶端一起使用,在ServerURI的情況下應該替換什么? 自從嘗試以下操作后,我如何放置機器的IP地址卻失敗了:
const string ServerURI = "http://ip:port";
我從SignalR = WebApp.Start(ServerURI);
行獲得了以下消息SignalR = WebApp.Start(ServerURI);
:
mscorlib.dll中發生了類型為'System.Reflection.TargetInvocationException'的未處理異常。其他信息:調用的目標已引發異常。
假設您將SignalR托管在某處的服務器上,則將使用服務器的主機名/ IP地址以及配置為監聽該端口的端口。
不幸的是,如果沒有有關引發異常的確切信息,那么很難提供更多幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.