Saturday, 15 January 2011

wifi - How to connect Android app to an static ip address -



wifi - How to connect Android app to an static ip address -

i trying develop app needs connect device via wifi. know ip address of other device, when seek connect it, not able.

private static string geturl(string direccion) throws connectexception{ seek { url u = new url("http://192.168.1.216"); httpurlconnection co = (httpurlconnection) u.openconnection(); bufferedreader reader = new bufferedreader(new inputstreamreader(co.getinputstream())); string line; while ((line = reader.readline()) != null) //buffer.append(line); system.out.println(line); reader.close(); co.disconnect(); system.out.println("######inputstream correcta... "+u); homecoming line; } grab (malformedurlexception e) { throw new connectexception(); } grab (java.net.connectexception e){ throw e; } grab (ioexception e) { throw new connectexception(); } }

you need specify these also:

co.setrequestmethod("get"); co.setdooutput(true); co.connect();

hence ,try :

private static string geturl(string direccion) throws connectexception{ seek { url u = new url("http://192.168.1.216"); httpurlconnection co = (httpurlconnection) u.openconnection(); co.setrequestmethod("get"); co.setdooutput(true); co.connect(); bufferedreader reader = new bufferedreader(new inputstreamreader(co.getinputstream())); string line; while ((line = reader.readline()) != null) //buffer.append(line); system.out.println(line); reader.close(); co.disconnect(); system.out.println("######inputstream correcta... "+u); homecoming line; } grab (malformedurlexception e) { throw new connectexception(); } grab (java.net.connectexception e){ throw e; } grab (ioexception e) { throw new connectexception(); }

}

android wifi ip-address connect

No comments:

Post a Comment