Can't access socket from external device on Android -


i wrote simple http-proxy android listening on device external ip address , specific port (e.g. 192.168.1.20:8080).

i can access ip/port device - tries external devices never accepted in run-loop.

the simplified code looks this:

public class mainactivity extends appcompatactivity  implements runnable {      private serversocket socket;     private int port = 8080;     private thread thread;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          wifimanager wm = (wifimanager) getsystemservice(context.wifi_service);         string ip = formatter.formatipaddress(wm.getconnectioninfo().getipaddress());          log.v("tag", "http://"+ip+":"+port);         try {             log.v("tag", inetaddress.getbyname(ip).tostring());             socket = new serversocket(port, 5, inetaddress.getbyname(ip));             socket.setsotimeout(5000);              thread = new thread(this);             thread.start();         } catch (exception e) {             e.printstacktrace();         }     }      @override     public void run() {         while (true) {             try {                 socket client = socket.accept();                 //  never reaches line if connected externally                 log.d("tag", "client connected");             } catch (sockettimeoutexception e) {             } catch (ioexception e) {                 e.printstacktrace();             }         }     } } 

i added permissions in androidmanifest.xml:

<uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.internet" /> 

but still no luck. out there can give advise?

thx.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -