views:

202

answers:

2

Hi,

could you please advice how to connect to development machine from device?

I can easily do this from Emulator, but from device I have connection timeout exception.

Here is my code:

String hostname = "10.0.2.2";
int port = 4444;

Socket socket = null;
try{
      socket = new Socket(InetAddress.getByName(hostname), port);
} catch(UnknownHostException e) {
      Log.e("Capturer","UnknownHostException : " + e.getMessage(), e); 
} catch(IOException e) {
      Log.e("Capturer", "IOException : " + e.getMessage(), e); 
}

Thanks

+2  A: 

Once you are on your device, you must use the actual (external visible) ipaddress/hostname for your development machine. If you connect via wifi with your device you should be able to use an internal(to your network) network ip address, if you are on 3g or edge, you will need your external, publicly visible ip address, if you have a network this will only get your to your modem/router, and you will need to setup the correct port forwarding for this to work.

broschb
+1  A: 

If you are just trying to send data from the device to the development machine for development purposes, you could also look into adb. In particular, check out adb forward. This would allow you to send data over the USB connection.

Daniel Yankowsky