java - Android device to PC's socket connection -
i facing problem establish socket connection android device pc's specific port 8080
. want create socket connect specific port , write data stream on port.
i have written code purpose code giving me exception as:
tcp error:java.net.connectexception:/127.0.0.1:8080-connection refused
i giving code below:
private static textview txtsendstatus; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); initcontrols(); string sentence = "tcp test #1n"; string modifiedsentence; try { socket clientsocket = new socket("192.168.18.116", 8080); dataoutputstream outtoserver = new dataoutputstream(clientsocket.getoutputstream()); bufferedreader infromserver = new bufferedreader(new inputstreamreader(clientsocket.getinputstream())); printscr("tcp connected."); outtoserver.writebytes(sentence + 'n'); modifiedsentence = infromserver.readline(); printscr(modifiedsentence); printscr("tcp success !!!"); clientsocket.close(); } catch (exception e) { printscr("tcp error: " + e.tostring()); } } private void initcontrols() { txtsendstatus = (textview)findviewbyid(r.id.txtsendstatus); } public static void printscr(string message) { txtsendstatus.append( "n" + message ); }
is there can tell me answer? waiting right answer.
best regards, gsmaker.
if using wifi, need use ip address of pc on wifi network. can find @ command line ifconfig (linux) or ipconfig (windows)
if using usb adb connection, can't this, can set adb port forward (see developer docs) pc phone, , have pc connect it's loopback interface , port, forwarded unprivileged port number on phone application should listening. have tcp or whatever connection can push data on in either direction. pc has initiator set connection - adb not support "reverse tethering" in phone initiates network-over-usb connections pc in way supported android emulator.
Comments
Post a Comment