java - Communicate Android Device to Localhost (My Windows 8 PC) over / via USB Cable -


i have android device samsung gt os 2.2.1

and have succeeded send http request localhost (my windows 8 pc) on wifi

but, considering of speed, want learn "how send http request localhost windows 8 pc on usb"

this code send on wifi

url url = null;         try {             /*wireless lan adapter local area connection*/         url = new url("http://192.168.xxx.xxx/myskripsi/testwritefile.php");         string body = "";         body += "text=" + messagetujuan;          byte[] bytes = body.getbytes();         httpurlconnection conn = null;         conn = (httpurlconnection) url.openconnection();         conn.setdooutput(true);         conn.setrequestmethod("post");         conn.setrequestproperty("content-type","application/x-www-form-urlencoded;charset=utf-8");         outputstream  out = conn.getoutputstream();          out.write(bytes);         out.close();         int status = conn.getresponsecode();          if (status != 200) {             toast.maketext(con, "status = " + status , 0).show();         }         else         {             inputstream = conn.getinputstream();              bufferedreader reader = new bufferedreader(new inputstreamreader(is));             stringbuilder sb = new stringbuilder();             string line = null;             try {                 while ((line = reader.readline()) != null) {                     sb.append((line + "\n"));                 }             } catch (ioexception e) {                 e.printstacktrace();             } {                 try {                     is.close();                  } catch (ioexception e) {                     e.printstacktrace();                  }             }             toast.maketext(con, "return nya = " +sb.tostring(), 0).show();             log.v("test" , "return nya = " + sb.tostring());             tv.settext(sb.tostring());             is.close();         }      } catch (exception e) {         toast.maketext(this, e.tostring() + "#" + e.getmessage(), 0).show();     } 

this code, give me result

but whenever turn off wifi shows

"java.net.socketexception: network unreachable"

so research through website, , found

http://www.codeproject.com/articles/191930/android-usb-port-forwarding

here print screen

http://imgur.com/qmhtoqu

and usb tunnel in android device "service running, connected !"

but , same code above, except :

url = new url("h**p://127.0.0.1:80/myskripsi/testwritefile.php"); 

the result "java.netconnectexception :/127.0.0.1:80 - connection refused"

i think there wrong firewall , dont know how fix

so question

is there other method can used communicate between android server?

i need my android device send data localhost (windows 8 pc) server , receive server's response on usb

thanks..

well, developed 1 application connect jsp file.here sample code.

              try                  {                      url url = new url("http:/xx.xxx.xxx.x:80/sample.jsp");                     httpurlconnection urlconnection = (httpurlconnection) url.openconnection();                      inputstream in = new bufferedinputstream(urlconnection.getinputstream());                      bufferedreader r = new bufferedreader(new inputstreamreader(in));                      string x = "";                      string total = "";                      int i=0;                      arraylist<string> content = new arraylist();                      while((x = r.readline()) != null)                      {                                  content.add(x);                       }                      in.close();                      r.close();                  }                  catch(exception e)                  {                      e.printstacktrace();                      toast.maketext(customer.this, e.tostring(), toast.length_short).show();                  } 

so,you can make change(in url) code wish.if want run in usb means, have download samsung usb driver pc , run application.before enable developer option in device.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -