0

I have been trying to initiate a socket connection within my application like this:

Socket socket =null;
try{
socket = new Socket("192.168.43.206",10000);
} catch(IOException e){
    Log.d("Socket ",e.getLocalizedMessage());
}

I have a TCP server running on my PC which is connected to the same router as the phone on which i am debugging. But when I debug and check the object socket it contains null and yet there were no exceptions caught. What am i doing wrong?

2 Answers2

2

(Would like to paste it as a comment, but have too little reputation)

Try catching the other exceptions and look if they are thrown: http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html

If you use linux, you can check if you can connect to that TCP connection (from PC) using netcat: [my]$ nc 192.168.43.206 10000

sygi
  • 4,557
  • 2
  • 32
  • 54
1

Check if you have added internet permission in manifest. i.e.

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

See related question

Community
  • 1
  • 1
Tech Agent
  • 657
  • 5
  • 12