-1

Android simple socket program client show false

 socket = new Socket(dstAddress, dstPort);
 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024);
 byte[] buffer = new byte[1024];
         int bytesRead;
         InputStream inputStream = socket.getInputStream();
         while ((bytesRead = inputStream.read(buffer)) != -1) {
            byteArrayOutputStream.write(buffer, 0, bytesRead);
            response += byteArrayOutputStream.toString("UTF-8");
         }
devcelebi
  • 878
  • 7
  • 11

1 Answers1

1

Try to use ip 10.0.2.xx (xx is a number) for emulator.

Each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine's network interfaces and settings and from the internet. An emulated device can not see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall

Ref: http://developer.android.com/guide/developing/devices/emulator.html#emulatornetworking

ductran
  • 10,043
  • 19
  • 82
  • 165
  • thank you for your answer. I try use 10.0.2.15 but not connection.I closed firewall but again not connection. – devcelebi Dec 12 '11 at 12:58
  • What is "not connection"? In client side try replace e.printStackTrace(); to Log.e(e.getMessage()); then see the logcat. – ductran Dec 13 '11 at 03:17