TOP | UP: Applied Frontier | NEXT: CGIs |
NetFrontier is an ingenious suite which makes it easy for Frontier to communicate with other copies of Frontier running remotely. Of course, it would be possible to arrange this yourself: for AppleTalk networks, you could build a Frontier glue table and send a remote copy of Frontier one of the five standard Apple events that it already knows how to receive; for TCP/IP, you could write a server with odbServer and communicate with it through a script like the one in Example 38-3. But NetFrontier does it all for you, and more:
Let's suppose we want a remote Frontier to report to us on the contents and file sizes of everything in its machine's system folder. We will use an approach which allows the scripts that do this to be developed and tested on our own machine.
We begin with a simple adaptation of samples.basicStuff.buildFolderOutline() .
workspace.outlineFolder() creates at scratchpad.otl an outline of the folder which is its parameter. But initially we don't necessarily know the pathname of the remote system folder, so here's a routine which queries the Finder about that, and hands the result to workspace.outlineFolder().
local (path) |
with objectmodel, finder |
path = get (startupdisk.systemfolder, 'TEXT') |
workspace.outlineFolder(path) |
Once we confirm that these routines work locally, our strategy is to transfer them both to the remote Frontier's database, call the remote workspace.outlineMaster(), retrieve the resulting remote scratchpad.otl, and then delete the remote scratchpad.otl, workspace.outlineMaster, and workspace. outlineFolder. This approach, called "put-run-delete," is very common.
NetFrontier's UserTalk interface provides four actions: remoteGet() , remotePut(), remoteDelete(), and remoteRun(). One should also clean up after a transaction by calling remoteQuit() . The script we shall use illustrates all of these verbs.
Literal addresses may be used in referring to the local database, but it is wise to use strings for addresses in the remote database, so that their validity as addresses will not be checked against the local database (see Chapter 8, Addresses, and compare our similar concerns in Chapter 30, Multiple Databases).
To prepare for execution, it is simplest to use NetFrontier's menu interface. First, choose NetFrontier from the Suites menu to bring up the menu interface. Now choose Edit Nodes from the Nodes submenu of the NetFrontier menu to designate the remote computer as a node.
All of the commands in outlineRemoteSysFolder() can take an optional parameter saying what node is to be communicated with, but if this is omitted, the "current node" is used. So, make sure that the remote computer is the "current node," with Select Current Node from the Nodes submenu. Now it is sufficient to click the Run button in the edit window of outlineRemoteSysFolder(). After a while, the outline of the system folder of the remote machine appears on the local machine.
If the remote computer is linked to the local computer by an AppleTalk network, NetFrontier works by creating and sending custom 'netf' Apple events to the remote Frontier. To see, for example, the heart of remoteGet(), look at netFrontier.ATclient.get() ; it sends a 'netf' /'valu' event, and the remote Frontier handles it with the script at system.verbs.traps.netf.valu.
But if the remote computer is linked to the local computer by a TCP/IP network, such as the Internet, Apple events are not involved. NetFrontier packages the call information and hands it over to tcpCmd (see Chapter 38, TCP/IP ), which in turn drives NetEvents to send the package across the network. At the remote station, another copy of NetEvents is functioning as a listener, and is being polled in a separate thread by a loop set up in netFrontier.TCPserver.listener() ; when the package arrives, the polling process picks it up and NetFrontier responds. It is only in this context that remoteQuit() does anything: it closes the connection between the two copies of NetEvents, returning the listener to listening and the local copy to an idle state; by including the call in Example 39-3, we ensure that the script will work over either AppleTalk or TCP/IP networks.
NetFrontier is well documented, at netFrontier.docs. The following points are worth noting.
TOP | UP: Applied Frontier | NEXT: CGIs |