Hy! I’m adapting a chat using sockets and threads from java client to android client. The server remains the same. I’ve wrote the internet and ACCESS_NETWORK_STATE permissions in the manifest. The problem is that when I try to connect to server it throws some errors.
The try{ socket = new Socket("localhost", 5000);} line throws:
What could be the problem ? Would you want to put the whole code here ?
I’m sure that you’re trying to contact your local machine and not the device itself. The phone will address itself using
localhostor127.0.0.1. So when your device is not a server and is not listening for that port the connection will fail.Try to use
10.0.2.2. This should target your machine you’re developing on. (source)