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!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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)


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x