I'm using a Task to read very fast from the socket and I have some problems with terminating the task.
Right now my code looks something like this:
sub init()
m.top.functionName = "readFromSocket"
end sub
sub readFromSocket()
socket = CreateObject("roStreamSocket")
...
while true
...
read very fast and process
end while
end sub
As you can see, the loop is infinite, the only time it ends is when the user requests it (back button on the remote), so I terminate the task with
m.task.control = "stop"
This works fairly good, but the problem is that the socket remains connected and the peer doesn't know that the connection ended.
Another solution I tried is this:
sub init()
m.top.functionName = "readFromSocket"
end sub
sub readFromSocket()
socket = CreateObject("roStreamSocket")
...
while not m.top.terminate
...
read very fast and process
end while
if socket.isConnected() then
socket.close()
end if
end sub
... and then to terminate the task I set the
m.task.terminate = true
The problem is that this solution is VERY slow. Lets say I get 30 loops a second in the "
while true", the "
while not m.top.terminate" will reduce the speed by half or more.
What's the best way to terminate a Task so I can close the socket connection while keeping the speed high?
https://github.com/e1ioan/
http://rokucam.com