Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

android - Accessing localhost(Xamarin)

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?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

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.

If that url is not available:

  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")

  3. 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)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...