java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -
when responding supplicant_state_changed_action
broadcast , attempting send udp packet, exception:
java.net.socketexception: sendto failed: eperm (operation not permitted) @ libcore.io.iobridge.maybethrowaftersendto(iobridge.java:542) @ libcore.io.iobridge.sendto(iobridge.java:511) @ java.net.plaindatagramsocketimpl.send(plaindatagramsocketimpl.java:184) @ java.net.datagramsocket.send(datagramsocket.java:305) @ com.mycompany.app.serviceclass.discover(serviceclass.java:355)at com.mycompany.app.serviceclass.access$600(serviceclass.java:39) @ com.mycompany.app.serviceclass$statemachine.run(serviceclass.java:242) @ java.lang.thread.run(thread.java:818) caused by: android.system.errnoexception: sendto failed: eperm (operation not permitted) @ libcore.io.posix.sendtobytes(native method) @ libcore.io.posix.sendto(posix.java:211) @ libcore.io.blockguardos.sendto(blockguardos.java:278) @ libcore.io.iobridge.sendto(iobridge.java:509) @ java.net.plaindatagramsocketimpl.send(plaindatagramsocketimpl.java:184) @ java.net.datagramsocket.send(datagramsocket.java:305) @ com.mycompany.app.serviceclass.discover(serviceclass.java:355) @ com.mycompany.app.serviceclass.access$600(serviceclass.java:39) @ com.mycompany.app.serviceclass$statemachine.run(serviceclass.java:242) @ java.lang.thread.run(thread.java:818)
is thrown android. during debugging or if thread.sleep()
call of ~300ms added prior attempting send packet, exception isn't raised. seems issue of simultaneous access socket.send()
method after android establishes network connection. debugging program 1 call made send()
, i'm confident issue related interaction between os , service.
the offending code similar to:
public class serviceclass extends service { private static final byte[] msg_bytes = "my string send".getbytes(); private connectionmonitor mconnmonitor; public void oncreate { super.oncreate(); // create new thread handle broadcast , register receiver mconnmonitor = new connectionmonitor(); mconnmonitorthread = new handlerthread("connectionmonitor", process.thread_priority_background) mconnmonitorthread.start(); looper connmonitorlooper = mconnmonitorthread.getlooper(); handler connmonitorhandler = new handler(connmonitorlooper); intentfilter intentfilter = new intentfilter(); intentfilter.addaction(wifimanager.supplicant_state_changed_action) registerreceiver(mconnmonitor, netintentfilter, null, connmonitorhandler); private void sendpacket() { datagramsocket sock = new datagramsocket(); // wrapped in try-catch try { datagrampacket packet = new datagrampacket(msg_bytes, msg_bytes.length, inetaddress.getbyname("239.255.255.250"), 1900); sock.send(packet); } catch (ioexception e) { // exception being raised } public class connectionmonitor extends broadcastreceiver { @override public void onreceive(context context, intent intent) { supplicantstate supplicantstate = intent.getparcelableextra(wifimanager.extra_new_state);
could network being taking more time initialize after supplicant completed
broadcast sent or more related threading within service?
Great, this article is pretty awesome and I have bookmarked this page for my future reference. Keep blogging like this with the latest information.
ReplyDeleteMulesoft Online Training
Mulesoft Training in Hyderabad
its awesome one to the public.i learnes many useful things from this
ReplyDeleteFull Stack Training in Chennai | Certification | Online Training Course | Full Stack Training in Bangalore | Certification | Online Training Course | Full Stack Training in Hyderabad | Certification | Online Training Course | Full Stack Training in Pune | Certification | Online Training Course | Full Stack Training | Certification | Full Stack Online Training Course