i'm trying create socket in android, keep on getting eaccess (permission denied) errors.
here code in separate thread ui thread.
public class client implements runnable { private final static string server_address = "173.246.12.125"; @override public void run() { try { inetaddress serveraddr = inetaddress.getbyname(server_address); datagramsocket socket = new datagramsocket(); ...
my android permissions include:
<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" /> <uses-permission android:name="android.permission.change_wifi_state" /> <uses-permission android:name="android.permission.change_network_state" />
and because of stackoverflow answers, added well:
<permission android:name="android.permission.internet"/>
but still cannot create socket.
what missing? error output:
java.net.socketexception: socket failed: eacces (permission denied) @ libcore.io.iobridge.socket(iobridge.java:623) @ java.net.plaindatagramsocketimpl.create(plaindatagramsocketimpl.java:93) @ java.net.datagramsocket.createsocket(datagramsocket.java:157) @ java.net.datagramsocket.<init>(datagramsocket.java:80) @ java.net.datagramsocket.<init>(datagramsocket.java:65) ... caused by: android.system.errnoexception: socket failed: eacces (permission denied) @ libcore.io.posix.socket(native method) @ libcore.io.blockguardos.socket(blockguardos.java:282) @ libcore.io.iobridge.socket(iobridge.java:608) @ java.net.plaindatagramsocketimpl.create(plaindatagramsocketimpl.java:93) @ java.net.datagramsocket.createsocket(datagramsocket.java:157) @ java.net.datagramsocket.<init>(datagramsocket.java:80) @ java.net.datagramsocket.<init>(datagramsocket.java:65) @ com.austinfathman.traffic_server.client.run(udp.java:73) @ java.lang.thread.run(thread.java:818)
i getting similar error. turns out if try bind port in use, won't work.
datagramsocket socket = new datagramsocket(3996);
this worked me.
Comments
Post a Comment