I wrote a simple java socket server. I can connect to it using my java client.
However when I try to connect an android device to it, it gives the following error : socket failed: eacces (permission denied)
Here is the code :
btnConvert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = txtText.getText().toString();
try {
Socket socket = new Socket("192.168.0.110", 7575);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println(text);
Toast.makeText(context, in.readLine(), Toast.LENGTH_SHORT).show();
in.close();
out.close();
socket.close();
}
catch(Exception e){
e.printStackTrace();
}
}
});
this line : Socket socket = new Socket("192.168.0.110", 7575);
seems to be the culprit.
I did some research and found the following links :
Error message 'java.net.SocketException: socket failed: EACCES (Permission denied)'
Android java.net.SocketException:socket failed: EACCES (Permission denied)
Android java.net.SocketException: socket failed: EACCES (Permission denied)
So, here is my manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.priyabrata.socketdemo" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
So what is going wrong ??