frondoc picture

What is Frontier?
Download
News & Updates

Web Tutorial
Scripting Tutorial
BBEdit Scripting
Directory

Mailing Lists
Sample Scripts
Verb Set
Frontier Site Outline

Search
Guestbook
BBS

User's Guide
1 2 3 4 5 6
7 8 9 10 11

Apple File Edit
Main Open Suites
Web Window

Menubar Outline
Script Table WP

frondoc picture

NetEvents Interface

Here's how we build on the NetEvents Apple Event interface in Frontier.

netEvents.launch

on launch () «Set up netEvents data in Frontier and launch the applet.
netEvents.init ()
return (app.startWithDocument ("NetEvents", ""))

netEvents.openStream

on openStream (adr, port) «Create a new stream
if typeOf (adr) != longType
adr = appleEvent (netEvents.id, 'WAPI', 'N2AD', '----', string (adr))
return (appleEvent (netEvents.id, 'WAPI', 'OPEN', '----', long (adr), 'PORT', short (port)))

netEvents.statusStream

on statusStream (stream, adrbytespending) «Get the status of a stream
local (vals)
complexEvent (@vals, netEvents.id, 'WAPI', 'STAT', '----', long (stream))
adrbytespending^ = vals.PEND
return (vals.['----'])

netEvents.readStream

on readStream (stream, bytesToRead) «Read from an open stream
return (appleEvent (netEvents.id, 'WAPI', 'READ', '----', long (stream), 'LENG', long (bytesToRead)))

netEvents.writeStream

on writeStream (stream, data) «Write data from an open stream
return (appleEvent (netEvents.id, 'WAPI', 'WRIT', '----', long (stream), 'DATA', string (data)))

netEvents.listenStream

on listenStream (port, flwaitloop = true, refcon = 0, timeout = 0)
«Set up a listener on the indicated port.
«If flwaitloop is true, we wait for a connection to be created.
netEvents.init () «make sure all the tables we need are set up
local (stream)
stream = appleEvent (netEvents.id, 'WAPI', 'LIST', '----', short (port), 'REFC', long (refcon), 'TIME', short (timeout))
local (adrtable = @user.netEvents.listens.[stream])
new (tabletype, adrtable)
adrtable^.ready = false
adrtable^.refcon = refcon
if flwaitloop
local (tc = clock.ticks ())
while not adrtable^.ready
if clock.ticks () > (tc + 1800) «30 seconds
local (bytespending)
netEvents.statusStream (stream, @bytespending) «keep the listen alive
tc = clock.ticks ()
sys.systemTask () «yield some time to other threads
return (stream) «the caller is now ready to start reading from the stream
listenStream (0)

netEvents.closeStream

on closeStream (stream) «Close a stream and delete the table representing it.
if defined (user.netEvents.listens.[stream])
delete (@user.netEvents.listens.[stream])
return (appleEvent (netEvents.id, 'WAPI', 'CLOS', '----', long (stream)))

netEvents.abortStream

on abortStream (stream) «Close a stream immediately
if defined (user.netEvents.listens.[stream])
delete (@user.netEvents.listens.[stream])
return (appleEvent (netEvents.id, 'WAPI', 'ABOR', '----', long (stream)))

netEvents.addressToName

on addressToName (adr) «Turn a four-byte number into a domain name
return (appleEvent (netEvents.id, 'WAPI', 'AD2N', '----', long (adr)))
«bundle «test code
«dialog.alert (addressToName (-839093064))

netEvents.nameToAddress

on nameToAddress (domainname) «Turn a domain name into a 4-byte number
return (appleEvent (netEvents.id, 'WAPI', 'N2AD', '----', string (domainname)))
«bundle «test code
«netEvents.nameToAddress ("www.scripting.com")
«-825485308

netEvents.addressDecode

on addressDecode (encodedAdr) «Turn a 4-byte number into a dotted IP address
local (s = string.hex (encodedAdr))
local (ip = "", i)
for i = 1 to 4
s = string.delete (s, 1, 2)
ip = ip + number ("0x" + string.mid (s, 1, 2)) + "."
return (string.mid (ip, 1, sizeof (ip) - 1))
bundle «test code
netEvents.addressDecode (-825485308)
«"206.204.24.4"

netEvents.addressEncode

on addressEncode (ipAddress) «Turn a dotted IP address into a 4-byte number
local (i, encoded)
for i = 1 to 4
encoded = (encoded * 256) + number (string.nthField (ipAddress, '.', i))
return (encoded)
«bundle «test code
«netEvents.addressEncode ("206.204.24.4")
«-825485308

netEvents.examples.manyThreads

local (domain = "ws3.scripting.com")
local (adroutline = @system.verbs.apps.netEvents.examples.scriptingPaths)
«local (domain = "www.biap.com")
«local (adroutline = @system.verbs.apps.netEvents.examples.biapPaths)
local (adrlist = {})
bundle
target.set (adroutline)
op.firstsummit ()
loop
adrlist = adrlist + op.getlinetext ()
if not op.go (down, 1)
break
target.clear ()
netEvents.launch ()
local (i)
for i = 1 to 10
local (ct=0)
if not defined (scratchpad.pages)
new (tabletype, @scratchpad.pages)
edit (@scratchpad.pages)
for item in adrlist
toys.threadCall ("netevents.examples.oneThread", {domain, item, "scratchpad.pages.page" + ct})
ct++
if mod (ct, 3) == 0
thread.sleepFor (1)
filemenu.save ()
thread.sleepFor (5)
while Frontier.countThreads () > 2
window.msg (clock.now ())
thread.sleepFor (1)

netEvents.examples.testListen

local (stream, s)
netEvents.launch ()
stream = netEvents.listenStream (80)
s = netEvents.readStream (stream, 10000)
toys.newtextobject (s, @scratchpad.request)
netEvents.writeStream (stream, "HTTP/1.0 200 OK\r\n\r\n" + "OH THE BUZZING")
netEvents.closeStream (stream)

netEvents.examples.whoIs

on whois (domain, server = "rs.internic.net")
local (stream = netEvents.openStream (server, 43))
local (s = "", bytespending)
netEvents.writeStream (stream, domain + "\r\n")
loop
case netEvents.statusStream (stream, @bytespending)
"CLOSING"
"CLOSED"
"INACTIVE"
break
"DATA"
s = s + netEvents.readStream (stream, bytespending)
netEvents.closeStream (stream)
return (s)
bundle «test code
netEvents.launch ()
if dialog.ask ("Who is?", @scratchpad.whois)
toys.newtextobject (whois (scratchpad.whois), @scratchpad.theyare)
edit (@scratchpad.theyare)

netEvents.examples.getDomains

local (iplist = {})
target.set (@netEvents.examples.ips)
op.firstSummit ()
loop
iplist = iplist + op.getLineText ()
if not op.go (down, 1)
break
target.clear ()
local (i, adrdomains = @netEvents.examples.domains, num, firstline = true, s)
new (outlinetype, adrdomains)
edit (adrdomains)
target.set (adrdomains)
for i = 1 to sizeof (iplist)
num = netEvents.addressEncode (iplist [i])
s = netEvents.addressToName (num)
if firstline
op.setLineText (s)
firstline = false
else
op.insert (s, down)
op.firstSummit ()
target.clear ()


© Copyright 1996-97 UserLand Software. This page was last built on 5/7/97; 1:21:33 PM. It was originally posted on 2/16/97; 8:16:18 AM. Internet service provided by Conxion.