Android Question java.io.IOException: Operation not permitted

nicieri

Active Member
Licensed User
Longtime User
Hi, I'm develop an App that send a UDP package every "x" time.

The problem is in "some devices" (In some it works perfectly without stopping.).. after working well for a long time, this error occurs:


SendData (01/11/2018 11:30:00): kp;BH901DCK5P;1;0;82
01/11/2018 11:30:00 184
java.io.IOException: Operation not permitted
at java.net.PlainDatagramSocketImpl.send(Native Method)
at java.net.DatagramSocket.send(DatagramSocket.java:696)
at anywheresoftware.b4a.objects.SocketWrapper$UDPSocket$1.run(SocketWrapper.java:479)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)

And this error is repeated every time that my app try to send the UDP Package.

Any idea?.. what can I do?
 

nicieri

Active Member
Licensed User
Longtime User
I tried this.. and the problem still:

Try
UDPSocket.Close
Sleep(2000)
Catch
Log("Error on close UDPSocket: " & LastException)
End Try
If UDPSocket.IsInitialized=False Then
UDPSocket.Initialize("UDP",7000,128)
End If
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
Hi.. If I create the UDPSocket every time that I need to send a package...

What happen?.. I need to dispose this object after send the package?

For example inside on my SendData Sub..

B4X:
Sub SendData()
      Dim UDPSocket as Socket...
...
..
    UDPSocket.Send...
    UDPSocket.Dispose()????
End Sub

Something like that.. or I don't need to dispose this object?
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
Ok Erel, thanks..

Can you answer the last question?.. can I add the UDPSocket in every Send? this is working now,.. but I don't know if I need to Dispose the object
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
I have the UDPSocket.Close and still the same error!.. I also have the Sleep(5000) afer UDPSocket.Send(Packet)

B4X:
If UDPSocket.IsInitialized=False Then
            UDPSocket.Initialize("UDP",7000,128)   'Port and buffer size can be changed
        End If
        Dim Packet As UDPPacket
        Dim bdata() As Byte
        bdata = data.GetBytes("ASCII")
        Packet.Initialize(bdata, ip,xxxx)   
        UDPSocket.Send(Packet)   
        Sleep(5000)
        UDPSocket.Close

Is the same Error:

java.io.IOException: Operation not permitted
at java.net.PlainDatagramSocketImpl.send(Native Method)
at java.net.DatagramSocket.send(DatagramSocket.java:696)
at anywheresoftware.b4a.objects.SocketWrapper$UDPSocket$1.run(SocketWrapper.java:479)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
The sleep is not the problem... I already did it, even with a timer I tried too and the problem persists.

The error persists even after the ".Close"
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
And look this error.. is one error and the other...

java.net.SocketException: sendto failed: EPERM (Operation not permitted)
at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:546)
at libcore.io.IoBridge.sendto(IoBridge.java:515)
at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:184)
at java.net.DatagramSocket.send(DatagramSocket.java:305)
at anywheresoftware.b4a.objects.SocketWrapper$UDPSocket$1.run(SocketWrapper.java:479)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: sendto failed: EPERM (Operation not permitted)
at libcore.io.Posix.sendtoBytes(Native Method)
at libcore.io.Posix.sendto(Posix.java:176)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278)
at libcore.io.IoBridge.sendto(IoBridge.java:513)
 
Upvote 0
Top