简体   繁体   English

当我尝试使用SignalR建立客户端和服务器连接时出错

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

相关问题 尝试使用connection.Start()连接到服务器时出现SignalR Client错误 - SignalR Client error when trying to connect to server with connection.Start() 建立SignalR连接时可以发送一些初始字母吗? - Can I send some initial when establishing SignalR connection? 建立与SQL Server的连接时出错 - Error establishing connection to SQL Server 建立与SQL Server的连接时发生与网络相关或特定于实例的错误-使用TempData时 - A network-related or instance-specific error occurred while establishing a connection to SQL Server - When using TempData 尝试创建数据库时出错:建立与SQL Server的连接时发生与网络相关或特定于实例的错误 - Error when trying to create DB: A network-related or instance-specific error occurred while establishing a connection to SQL Server 当我使用不带连接字符串的服务器资源管理器时,如何在客户端系统中安装我的应用程序 - How to instal my application in client system when I am using server explorer without connection string SignalR 服务器在客户端连接时立即关闭连接 - SignalR server closes connection immediately when the client connects 当我附加mdf文件时,与SQL Server建立连接时发生与网络相关的错误或特定于实例的错误 - A network related error or instance-specific error occured while establishing a connection to sql server when i attach mdf file 当我尝试与我的数据库建立连接时出现错误 - Getting an error when I am trying to make a connection with my database 在宿主模式下,DDE服务器未建立连接 - DDE server not establishing connection when in hosted mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM