I'm trying to setup a TCP connection between my Android phone and my Raspberry Pi. Should be easy, turns out it isn't ? So i started writing a simple server with ServerSocket. It didn't work so i reduced the code until i got this piece which is not working:
try
{
String wifiip = wifiIpAddress(this);
Log.v("SERVER", wifiip);
ServerSocket serverSocket = new ServerSocket();
serverSocket.setReuseAddress(true);
serverSocket.bind(new InetSocketAddress(wifiip, 4117));
}catch (Exception ex)
{
ex.printStackTrace();
}
(The code is located in the onCreate method in my MainActivity which was created by AndroidStudio)
I also tried to create the ServerSocket with this method with no success.
ServerSocket serverSocket = new ServerSocket(4117);
The method wifiIpAddress was taken from here: https://stackoverflow.com/a/18638588/2394967 and works just fine.
The AndroidManifest.xml
<manifest ...>
<uses-sdk android:targetSdkVersion="21"></uses-sdk>
<uses-permission android:name="ANDROID.PERMISSION.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
...
</manifest>
Maybe useful informations:
Logcat
java.net.SocketException: socket failed: EACCES (Permission denied)
W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:632)
W/System.err﹕ at java.net.PlainSocketImpl.create(PlainSocketImpl.java:198)
W/System.err﹕ at java.net.PlainServerSocketImpl.create(PlainServerSocketImpl.java:38)
W/System.err﹕ at java.net.ServerSocket.<init>(ServerSocket.java:64)
W/System.err﹕ at eu.therealskynet.socketstest.MainActivity.onBtSendClicked(MainActivity.java:47)
W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err﹕ at android.view.View$1.onClick(View.java:4078)
W/System.err﹕ at android.view.View.performClick(View.java:4832)
W/System.err﹕ at android.view.View$PerformClick.run(View.java:19839)
W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err﹕ at android.os.Looper.loop(Looper.java:211)
W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5333)
W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
W/System.err﹕ Caused by: android.system.ErrnoException: socket failed: EACCES (Permission denied)
W/System.err﹕ at libcore.io.Posix.socket(Native Method)
W/System.err﹕ at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282)
W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:617)
W/System.err﹕ ... 17 more
I don't even know what "socket failed: EACCES (Permission denied)" is supposed to tell me...
I'll just post the answer myself.
The problem was that this is case sensitive:
ANDROID.PERMISSION.INTERNET
And has to be written like this:
android.permission.INTERNET
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With