Android - Locate IP of WAMP Server on a Local Netwiok -
can me? i'm doing android application project.
but late me know mysql not entirely compatible android.
i can't go now. title said using wamp server host mysql database on local netwok computer.
and read (correct me if i'm wrong) need actual ip of computer grab data wamp server.
if @ given moment ip of hosting computer changes, android application won't able connect mysql database.
is there anyway ip of hosting computer programtically?
i tried using current ip address of device network ip.
example:
device ip 192.168.1.2 , hosting computer ip 192.168.20, know network ip 192.168.1.1. loop 192.168.1.2 until 192.168.1.254, loop break/stop if got response needed. saves ip string.
public string isconnectedtoserver(string url, int index) { strictmode.threadpolicy policy = new strictmode.threadpolicy.builder() .permitall().build(); strictmode.setthreadpolicy(policy); string result = ""; for(int octet = 2; octet <= 254; octet++) { string compare = ""+octet; if(!compare.equals(url.substring(index + 1, url.length()))) { try { httpurlconnection.setfollowredirects(false); httpurlconnection con = (httpurlconnection) new url("http://" + url.substring(0, index + 1) + "" + octet + "/avmssv2").openconnection(); con.setrequestmethod("head"); con.setrequestproperty("user-agent", "android application"); con.setrequestproperty("connection", "close"); //toast.maketext(login.this, "network connected", toast.length_long).show(); if (con.getresponsecode() == httpurlconnection.http_ok) { result = "http://" + url.substring(0, index + 1) + "" + octet + "/avmssv2/pages/android.php"; break; } else { result = ""; } log.w("app", "network"); } catch (exception e) { // handle exceptions //toast.maketext(login.this, "network error connection", toast.length_long).show(); log.e("app", "exception", e); result = ""; } } } return result; }
the above code example of mine not seem work. , used asynctask. feel free give me suggestion.
p.s. problem can't change different database. because current project multi-platform. that's why need stick mysql because other platform using.
and wish stick dynamic host of ip possible.
use router set static ip address of database server.
then solve 2 problems. 1) won't change ip addresses , 2) don't need worry programming above you'll know ip address
Comments
Post a Comment