Non blocking question
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Non blocking question
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
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
Re: Non blocking question
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.
Some examples of blocking and non-blocking code from a search on the same.

Re: Non blocking question
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
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
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Non blocking question
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
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Non blocking question
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!
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!


Re: Non blocking question
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
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
Re: Non blocking question
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
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
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Non blocking question
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.
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Non blocking question
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
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
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Non blocking question
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Non blocking question
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
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
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Non blocking question
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Non blocking question
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.
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)
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...

Re: Non blocking question
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.Instead of an answer dialog, you could make a modal dialog out of a sub stack
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
HyperActive Software | http://www.hyperactivesw.com