Non blocking question

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Non blocking question

Post by Pistris » Tue Feb 26, 2019 10:46 pm

Can someone explain in layman terms what blocking and non blocking
means in the context of using sockets, I don't get it by reading at the help

thank you so much

PS: or point me to a thread that explains it, I could not find one

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Non blocking question

Post by bogs » Tue Feb 26, 2019 11:43 pm

Hm. Blocking and Non-blocking mean the same thing regardless of the context, 'blocking' simply means that nothing else is going to happen until event x is finished. 'Non-blocking' means something else *can* happen before event x is finished.

Some examples of blocking and non-blocking code from a search on the same.
Image

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Non blocking question

Post by Pistris » Tue Feb 26, 2019 11:58 pm

When you say nothing else is going to happen you mean the LiveCode engine is doing nothing else?
All the other events don’t get triggered ? Or they wait to get triggered?

Nothing else happens is too broad, what is exactly not happening?

I couldn’t find this in the LiveCode help

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Non blocking question

Post by FourthWorld » Wed Feb 27, 2019 12:03 am

With sockets, non-blocking can be especially useful for two reasons:

1. Network I/O often comes at cost of latency

2. By using callbacks you're effectively handing off the management and buffering of the socket transaction to the OS, which is a threaded operation.

This is my favorite tutorial for learning sockets in LiveCode. It uses the callback option throughout so it teaches how non-blocking calls work with LC's networking, and when you're done you have a foundation on which you can build all sorts of client-server stuff:
http://lessons.livecode.com/m/4071/l/12 ... ng-sockets
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Non blocking question

Post by bogs » Wed Feb 27, 2019 12:16 am

When I say nothing else is going to happen, I mean in context of the next line of code is not going to execute until the blocking code is done.

If you were talking about, for instance, blocking and non blocking dialogs, an answer or ask dialog would be a good example of a 'blocking' dialog. When one shows up, you aren't able to go back to your main program until you complete the dialogs requirement, even if it is just you hitting cancel to dismiss it.

A modal dialog, on the other hand, is non-blocking because it lets the dialog appear, *but* you can still interact with the rest of the program, and it will wait for whatever time you have to dismiss it.

It is the same in code. The code executes line by line, for the most part, but there are still ways to do the same thing either with a script that is 'blocking' or 'non-blocking'.

The best examples I've seen of doing the same thing each way were the '99 bottles of beer' blocking and non-blocking -
http://lessons.livecode.com/m/2592/l/12 ... n-blocking
http://lessons.livecode.com/m/2592/l/12 ... n-blocking

There was also a lesson about downloading a url blocking/non-blocking, which also goes into a somewhat clearer idea of what goes on behind the scenes -
http://lessons.livecode.com/m/4071/l/75 ... revolution

* I see Richard chimed in with the best information, but screw it, I already typed this! :P
Image

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Non blocking question

Post by Pistris » Wed Feb 27, 2019 12:20 am

Ok let me illustrate better

I have coded a middleware program to serve between my MySQL databases and mobile apps
The program has a simple graphic interface that provides me with stats and tells me what going on

Today I added a button that gets all the stats and exports them into a text file and I added a pop up that says
‘Export Ok’ once it finishes writing the file to hard drive

After I click on the ok button, every query that the program received between the popup and me hitting the ok
Button, they get bundled together in one string.
So the handler receivedmmesage does not execute while the popup window is active
Then I hit ok and it tries to run a query that is the combination of lots of queries together

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Non blocking question

Post by Pistris » Wed Feb 27, 2019 12:27 am

So every time data comes on the socket a message called messageReceived should be called
But does not get called while the popup (answer) is active

Now am thinking that I should add some sort of delimiter when I transmit the query so I can process it

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Non blocking question

Post by FourthWorld » Wed Feb 27, 2019 12:32 am

If your "popup" is using the answer dialog, the answer command is blocking. That is, nothing happens until the dialog is closed and execution moves on to the next statement.

So if you had socket work in progress with callbacks, it is very likely indeed that it would complete while the dialog is up, and the calls backs would all fire in quick sequence once the dialog is dismissed.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Non blocking question

Post by Pistris » Wed Feb 27, 2019 12:52 am

Well the problem is they don’t fire in sequence after
It just fires one time with every piece of data that arrived at the socket lumped together

Am gonna insert a phrase at the end of each query so I can process the data string in the event
that any blocking occurs.

Am gonna do a lot of testing tonight am come back with some answers

Thank you guys

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Non blocking question

Post by FourthWorld » Wed Feb 27, 2019 2:25 am

What does the code look like?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Non blocking question

Post by Pistris » Wed Feb 27, 2019 4:59 am

this is the handler that gets called every time data is received on the socket

under normal operation I would receive on the socket strings like this
SELECT * FROM employedb WHERE SALARY > 20000;

if the pop up widow message is active (am referring to an answer command)
then I could get a string that looks like this

SELECT * FROM employedb WHERE SALARY > 20000;SELECT * FROM employedb WHERE membersince = 1990;

it will put together everything coming in
and I just realized doing some testing that the same happens if the data being transmitted is too short

am gonna have to include some word at the beginning so I can process the data, example

STARTDATA SELECT * FROM employedb WHERE SALARY > 20000; ENDDATA

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Non blocking question

Post by FourthWorld » Wed Feb 27, 2019 7:17 am

The SQL statements may be useful, but what we really need to see is the LiveCode Script.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Non blocking question

Post by bogs » Wed Feb 27, 2019 11:33 am

I'm with Richard, seeing the livecode scripting your using would be the easiest way to diagnose, but some ideas come to mind from the description.
Pistris wrote:
Wed Feb 27, 2019 4:59 am
if the pop up widow message is active (am referring to an answer command)
Instead of an answer dialog, you could make a modal dialog out of a sub stack. Data from your other program should continue running in the background (non blocking, refer to my dialog post).

Look into using 'with messages' statements.

Alternately, set the part that determines the string to use itemDelimiter set to ";", and structure it so that each item goes onto a new line in a variable. For example (psuedo)

Code: Select all

// handler that sets up the string...
on yourHandlerForString
   set the itemDelimiter to ";"
   
   repeat with x=1 to the number of items of {yourStringDataSource}
     do xyz with item x of {yourStringDataSource}
   end repeat
   
end yourHandlerForString
// the rest of your code...

Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7392
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Non blocking question

Post by jacque » Wed Feb 27, 2019 6:02 pm

Instead of an answer dialog, you could make a modal dialog out of a sub stack
Just an LC terminology note: ask and answer dialogs are modal. Modal stacks prevent user interaction until they are dismissed. I think you mean "modeless" which does allow other interaction.

I'm guessing that other IDEs may refer to them differently, given your experience with those.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Non blocking question

Post by bogs » Wed Feb 27, 2019 8:50 pm

:oops: :oops: :oops:
(going out to bury my head in a snow bank)
:oops: :oops: :oops:
Image

Post Reply