android serversocket 权限,java - Android - ServerSocket permission denied - Stack Overflow
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 reduce
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
...
Maybe useful informations:
I'm running AndroidStudio on ArchLinux
I tried using a new, untouched Project
I tried different Ports (above 1024)
I'm running the App on a real device (Xperia Z, Android 5.0.2)
I tried running the ServerSocket in another thread
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.(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...
更多推荐
所有评论(0)