[英]Error when I am trying to establishing a client and server connection using SignalR
I am trying to create a server client communication using SignalR . 我正在尝试使用SignalR创建服务器客户端通信。 I have manage to perform that communication locally.
我设法在本地执行该通信。 My server side code is the following:
我的服务器端代码如下:
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(); }
}
The code is working with clients which located in the same mahcine. 该代码正在与位于同一机器中的客户端一起使用。 I want to work with clients in the same lan however not in the same machine.
我想与同一局域网中的客户端一起工作,但不在同一台计算机中。 What should I replace in the case of ServerURI in order to be able to work with clients which are not in the same machine?
为了能够与不在同一台计算机上的客户端一起使用,在ServerURI的情况下应该替换什么? How can I put the ip of the machine since when I am tried the following I failed:
自从尝试以下操作后,我如何放置机器的IP地址却失败了:
const string ServerURI = "http://ip:port";
and I got the following message from the line SignalR = WebApp.Start(ServerURI);
我从
SignalR = WebApp.Start(ServerURI);
行获得了以下消息SignalR = WebApp.Start(ServerURI);
: :
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll Additional information: Exception has been thrown by the target of an invocation.
mscorlib.dll中发生了类型为'System.Reflection.TargetInvocationException'的未处理异常。其他信息:调用的目标已引发异常。
Assuming you're hosting SignalR on a server somewhere, you'd use the hostname/IP address of the server and the port that it's configured to be listening to for this. 假设您将SignalR托管在某处的服务器上,则将使用服务器的主机名/ IP地址以及配置为监听该端口的端口。
Unfortunately, without additional information about what exactly threw the exception, it's hard to give much additional help. 不幸的是,如果没有有关引发异常的确切信息,那么很难提供更多帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.