Skip to content Skip to sidebar Skip to footer

Unable To Create Android Client Socket

I'm trying to create an android client app that connects to a server on my desktop. I successfully telneted to the server from my laptop. I have put INTERNET and NETWORK permission

Solution 1:

I understood that the android app is running in the emulator on the server desktop. So first of all you need to change that LAN IP 192.168.x.x

Blockquote When working with the Android emulator, you may frequently need to access data hosted on the local web server using localhost. For example, your own web services are likely to be hosted on your local computer during development, and you’ll want to test them on the same development machine you use to write your Android applications. In such cases, you should use the special IP address of 10.0.2.2 (not 127.0.0.1) to refer to the host computer’s loopback interface. From the Android emulator’s perspective, localhost (127.0.0.1) refers to its own loopback interface.

cited from http://p2p.wrox.com/book-beginning-android-application-development-631/

Then if the android app is not in running in the server I guess you need some extra lines to avoid errors:

serverAddress =
InetAddress.getByName(“192.168.1.142”);
//--remember to change the IP address above to match your own-- and also the port
socket = newSocket(serverAddress, 500);

And also I'm asumming you're doing inside the extends AsyncTask class.

Post a Comment for "Unable To Create Android Client Socket"