【问题标题】:SignalR: Binding localhost vs all addressesSignalR:绑定本地主机与所有地址
【发布时间】:2014-03-04 05:47:19
【问题描述】:

在 SignalR 教程中:http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-self-host

    static void Main(string[] args)
    {
        // This will *ONLY* bind to localhost, if you want to bind to all addresses
        // use http://*:8080 to bind to all addresses. 
        // See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx 
        // for more information.
        string url = "http://localhost:8080";
        using (WebApp.Start(url))
        {
            Console.WriteLine("Server running on {0}", url);
            Console.ReadLine();
        }
    }

什么时候只绑定到本地主机,什么时候选择绑定到所有地址?

我觉得这很奇怪,因为我在服务器和客户端上都指定了localhost

这是我作为 Windows 服务托管的客户端代码

            var hubConnection = new HubConnection("http://localhost:8080/");
            IHubProxy hubProxy = hubConnection.CreateHubProxy("MyHub");
            hubProxy.On<string, string>("addMessage", (name, message) =>
            {
                Log.Info(string.Format("Incoming data: {0} {1}", name, message));
            });
            ServicePointManager.DefaultConnectionLimit = 10;
            await hubConnection.Start();

当我的服务器绑定到所有地址时,客户端工作

string url = "http://*:8080";

如果我只绑定到本地主机,我的客户端不会收到来自服务器的任何消息。

【问题讨论】:

    标签: c# .net signalr


    【解决方案1】:

    您是否在同一台机器上运行客户端和服务器?如果没有,'localhost' 将不起作用。请尝试改用机器名称。

    【讨论】:

    • 是的,是同一台机器。
    猜你喜欢
    • 2020-12-10
    • 2021-09-24
    • 2010-09-06
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多