访问本地主机(Xamarin) [英] Accessing localhost(Xamarin)

查看:90
本文介绍了访问本地主机(Xamarin)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用SignalR在我的android应用中实现聊天,我从asp.net下载此示例: https://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr 但是我不能通过HubConnection使用localhost来访问它.我尝试使用我的IP地址和端口号,但是它不起作用.有人有经验吗?

I want to implement chat in my android app using SignalR and I download this example from asp.net: https://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr But I can't acces to it using localhost through HubConnection. I tried using my IP adress and port number but it's not working. Does anyone has experience with this?

谢谢!

推荐答案

假设您的应用服务器是IIS Express,则由于网络限制甚至防火墙的限制,它在默认情况下将不起作用.

Assuming your app server is IIS Express, it won´t work by default because of network restrictions or even the firewall.

第一件事,正如您已经意识到的那样,客户端需要连接您的计算机ip,而不是本地主机.类似于 http://x.x.x.x:port/signalr

First thing, as you already realized, the client needs to connect with your machine ip, not localhost. Something like http://x.x.x.x:port/signalr

然后,您需要确保您的计算机可以通过手机或仿真器访问:在手机中打开浏览器,然后键入一个已知地址,例如 http://xxxx:port/somethingThatExists .

Then you need to make sure your machine is accesible from the mobile phone or emulator: open a browser in the phone and type a known address, like http://x.x.x.x:port/somethingThatExists.

如果该网址不可用:

  1. 尝试禁用防火墙
  2. 在运行IIS-Express的计算机上打开powershell并运行以下命令: netsh http add urlacl url = http://{您的服务器ip}:{port}/user = everyone .(如果您的系统语言不是英语,例如:西班牙语,请将所有人"更改为"todos")

  1. Try disabling the firewall
  2. Open powershell at the machine runing IIS-Express and run this: netsh http add urlacl url=http://{your server ip}:{port}/ user=everyone. (if your system language is not english, for instance: spanish, change "everyone" to "todos")

在目录解决方案 Solution/.vs/config/applicationhost.config 中打开文件 applicationhost.config ,然后搜索应用程序xml节点.类似于< site name ="YourAppName" id ="1"> ...</site> .默认情况下,您将看到 localhost 绑定.添加一个带有实际ip的新IP:< binding protocol ="http" bindinginformation ="*:port:xxxx"</binding> (确保ip/port正确.即: *:57457:192.168.0.57 )

Open the file applicationhost.config in your directory solution Solution/.vs/config/applicationhost.config and search for the application xml node. Something like <site name="YourAppName" id="1">...</site>. You´ll see the localhost binding by default. Add a new one with the actual ip: <binding protocol="http" bindinginformation="*:port:x.x.x.x"></binding> (make sure the ip/port are correct. i.e: *:57457:192.168.0.57)

重新启动IIS Express,然后重试(无需重新启动系统)

Restart IIS Express and try again (no need to reboot the system)

这篇关于访问本地主机(Xamarin)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆