Re: [NTLK] newtonscript, NIE and confusion

From: Eckhart Köppen (eck1001_at_gmx.net)
Date: Thu Apr 29 2004 - 08:51:23 PDT


Been there, done that ;) - you are 100% right. It shouldn't be so
complicated! But there are four reasons why things are the way they are:

1. There are no threads and almost all I/O is non-blocking on the
Newton. This requires that you use callbacks throughout your code. And
that almost always leads to state machines.
2. You have to deal with connecting to the Internet, something that you
can usually take for granted on a desktop machine. On the Newton, this
is what the Link Manager does. And the Link Manager is of course
asynchronous!
3. The basic communication channel is the Endpoint, and that was
designed to be agnostic regarding the communications medium.
Unfortunately, the way of setting medium specific information (e.g.
TCP/IP addresses or serial speeds) gets more complicated, and you have
to deal with Endpoint Options.
4. Endpoints want to know something about the data they are supposed to
receive so that communication ends at certain points (e.g. when a
newline character comes in). Reading unknown amounts of data is a bit
tricky, and the fallback of reading one byte at a time is quite slow.

The Thumb code does everything by the book. It covers all cases, is
very flexible (and then somehow not ;) and really neat. But I had the
same problem as you when starting with NHttpLib: It is hard to
understand because it has a really steep learning curve!

There are a couple of things you can do:

- get used to the state machine approach (not the Thumb thing!) step by
step. A good start is the Link Manager. You could model acquiring and
releasing a link as a separate object/frame with state information and
callbacks. The next step would be to extend that to deal with Endpoints.
- Waba contains some NewtonScript code which bascially turns acquiring
a link into one synchronous function call. That code has some neat way
of dealing with the whole callback thing and user interaction, i.e. it
uses a dialog box to block execution until something else is ready (the
DoProgress global function)
- you could use NHttpLib (start looking at the protoNHttpLib:MGet
function) and rip out those methods which send, receive and disconnect,
so you'd use it only to grab the link and connect.

Eckhart

-- 
This is the NewtonTalk list - http://www.newtontalk.net/ for all inquiries
Official Newton FAQ: http://www.chuma.org/newton/faq/
WikiWikiNewt for all kinds of articles: http://tools.unna.org/wikiwikinewt/


This archive was generated by hypermail 2.1.5 : Thu Apr 29 2004 - 09:00:06 PDT