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
|
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. |
| 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 |
| complexEvent (@vals, netEvents.id, 'WAPI', 'STAT', '----', long (stream)) |
| adrbytespending^ = vals.PEND |
|
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 |
| stream = appleEvent (netEvents.id, 'WAPI', 'LIST', '----', short (port), 'REFC', long (refcon), 'TIME', short (timeout)) |
| local (adrtable = @user.netEvents.listens.[stream]) |
| new (tabletype, adrtable) |
| adrtable^.refcon = refcon |
| local (tc = clock.ticks ()) |
| while not adrtable^.ready |
| if clock.ticks () > (tc + 1800) «30 seconds |
| netEvents.statusStream (stream, @bytespending) «keep the listen alive |
| sys.systemTask () «yield some time to other threads |
| return (stream) «the caller is now ready to start reading from the stream |
|
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))) |
| «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))) |
| «netEvents.nameToAddress ("www.scripting.com") |
|
netEvents.addressDecode
on addressDecode (encodedAdr) «Turn a 4-byte number into a dotted IP address |
| local (s = string.hex (encodedAdr)) |
| s = string.delete (s, 1, 2) |
| ip = ip + number ("0x" + string.mid (s, 1, 2)) + "." |
| return (string.mid (ip, 1, sizeof (ip) - 1)) |
| netEvents.addressDecode (-825485308) |
|
netEvents.addressEncode
on addressEncode (ipAddress) «Turn a dotted IP address into a 4-byte number |
| encoded = (encoded * 256) + number (string.nthField (ipAddress, '.', i)) |
| «netEvents.addressEncode ("206.204.24.4") |
|
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) |
| adrlist = adrlist + op.getlinetext () |
| if not defined (scratchpad.pages) |
| new (tabletype, @scratchpad.pages) |
| toys.threadCall ("netevents.examples.oneThread", {domain, item, "scratchpad.pages.page" + ct}) |
| while Frontier.countThreads () > 2 |
| window.msg (clock.now ()) |
|
netEvents.examples.testListen
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") |
| case netEvents.statusStream (stream, @bytespending) |
| s = s + netEvents.readStream (stream, bytespending) |
| netEvents.closeStream (stream) |
| if dialog.ask ("Who is?", @scratchpad.whois) |
| toys.newtextobject (whois (scratchpad.whois), @scratchpad.theyare) |
| edit (@scratchpad.theyare) |
|
netEvents.examples.getDomains
target.set (@netEvents.examples.ips) |
| iplist = iplist + op.getLineText () |
local (i, adrdomains = @netEvents.examples.domains, num, firstline = true, s) |
new (outlinetype, adrdomains) |
for i = 1 to sizeof (iplist) |
| num = netEvents.addressEncode (iplist [i]) |
| s = netEvents.addressToName (num) |
|
© 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.
|