android volley library does not work on local IP

邮差的信 提交于 2020-01-24 19:34:06

问题


volley is not working when i want to fetch data from a system on my local network. where URL is like http://192.168.x.x/data.php it works well on emulator but not on a real device. it show a time our error. even i tried setting a maximum time our and retry policy. but in vain.


回答1:


There are two ways to solve this:

a) keep your device connected to the PC which is connected to your local network either using lan or wifi. Keep debugging mode on. Use ipconfig to check your pcs ipv4 address and use that.

forward your server's port on your router and then use the ipv4 address found on your pc's ipconfig command.

c) Best option-> i use this. Forward your pc's server port on your router, Go to your router's DHCP configurations and give your pc mac a preferred DHCP ip to make sure your router always gives that local ip to your pc(global will still be dynamic if you dont have a static ip). Register to a DDNS and use the set ip above and you will be able to access your web service from anywhere in the world. (i use dynudns for the ddns part)

see How can I access my localhost from my Android device? for other ideas

In the first two steps, make sure that the mobile is connected via wifi so that the router can forward it requests. in third, it can be connected to the internet anyway it likes. Also in the first, you will have to change the url everytime your local ip changes.

In second option, the dns will give a tool for auto ip updation :)



来源:https://stackoverflow.com/questions/38496799/android-volley-library-does-not-work-on-local-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!