r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3 Schemes] Implementors guide

eFishAnt
10-Jan-2010
[795x4]
Gregg made a cool FSM dialtect years ago.
dialect
is there a trick to read R3 dns:// ?  I haven't found it.  Didn't 
see any tickets in cure-code.  Should something be submitted there? 
 (last year was 100% R2 product design...I am wanting to port some 
Core stuff to R3, but I need as much network stuff as possible.  
I did write a real-time video codec for R3 a couple years ago...I 
might see if it can hook into the new codec stuff, too.
on-topic as it was also networked...;-)
Graham
10-Jan-2010
[799x3]
There isn't a dns:// scheme written yet.
there is a low level dns lookup occuring in the tcp device ...
fish ... naughty .. you haven't released your video codec for R3
eFishAnt
10-Jan-2010
[802x3]
my bad...was waiting to get real binary numbers so the code shrinks 
to half the size...100% rebol code, too.  Also, I have to figure 
how to hook into the R3 codec infrastructure...and still trying to 
remember my password for R3 chat.
there is a dns://scheme but the usage is either unknown or broken.
print first read dns://www.rebol.com returns none instead of an IP 
tuple
Graham
10-Jan-2010
[805x4]
so this is a r3 video codec?
I find it hard to believe that you wrote this two years ago with 
so little documentation available then!
To get the ip address I suspect all you have to do is do a query 
on a port once the lookup has completed
the dns:// scheme is there .. it's just not finished ...
eFishAnt
10-Jan-2010
[809x3]
It was in the last half of 2007 I wrote it.  R3 was fast enough for 
real-time.
So how do I "query" a port?
my R3 need with DNS is to be able to tell if a domain is there or 
was it mistyped, to prevent calamity
Graham
10-Jan-2010
[812x4]
in the awake handler, there is a 'lookup event
inside this event, use query port
I'm guessing here of course :)
rebol []
make-scheme [
	name: 'dns2
	title: "DNS Protocol"
	spec: make system/standard/port-spec-net [port-id: 80]


	awake: funct [event ] [
		print ["=== Client event:" event/type]
		client: event/port
		switch event/type [
			lookup [
				; print "DNS lookup"
				probe query client
				return true
			]
			connect []
		]
	]
	actor: [
		open: func [
			port [port!]
			/local conn
		] [
			if port/state [return port]
			if none? port/spec/host [http-error "Missing host address"]
			; set the port state
			port/state: context [
				state:
				connection:
				error: none
				awake: none ;:port/awake
				close?: no
			]
			; create the tcp port and set it to port/state/connection
			port/state/connection: conn: make port! [
				scheme: 'tcp
				host: port/spec/host
				port-id: port/spec/port-id
				ref: rejoin [tcp:// host ":" port-id]
			]
			conn/awake: :awake
			open conn
			print "port opened ..."
			; return the newly created and open port
			wait conn
			conn
		]
	]
]

open dns2://www.rebol.com
Pekr
10-Jan-2010
[816]
open? will read work too? Feels weird ...
Graham
10-Jan-2010
[817x2]
what do you mean?
Hmm.. why can't I overwrite the existing scheme?
Pekr
10-Jan-2010
[819]
I mean - I was used to get data by using 'read, not 'open .... Open 
just always opened the port, nothing more ... now try following with 
your solution:

print read dns://www.rebol.com
Graham
10-Jan-2010
[820x2]
Don't understand.
I only wrote an open actor for my dns scheme
Steeve
10-Jan-2010
[822]
Should be enough

make-scheme [
	title: "Dns"
	name: 'dns2
	actor: [
		read: func [port [port!] /con][
			con: open [scheme: 'tcp host: port/spec/host]
			con/awake: func [event][true]
			wait [con 5]  ;*** timeout 5 secs
			attempt [get in query con 'remote-ip]
		]
	]
]
>>read dns2://www.rebol.net
216.240.11.203
Graham
10-Jan-2010
[823]
Thanks Steeve!
Steeve
10-Jan-2010
[824x2]
not that i don't need to close the tcp port because it is not (really) 
opened yet
not=notice
Graham
10-Jan-2010
[826x2]
I didn't open the port either
Normally one would open the port in the lookup event
Steeve
10-Jan-2010
[828]
yep
Graham
10-Jan-2010
[829x2]
Andreas likes to use funct so no need to declare the locals
Now how to do a reverse dns lookup??
Steeve
10-Jan-2010
[831]
i don't have any idea how to do that
Graham
10-Jan-2010
[832x2]
>>read reverse dns2://216.240.11.203
www.rebol.net
oops ... someone made this group web public!
Steeve
10-Jan-2010
[834]
ahah
Pekr
10-Jan-2010
[835]
we can change it back ...
Graham
10-Jan-2010
[836x2]
the above was a joke!  please ignore
reverse lookups http://cr.yp.to/djbdns/intro-dns.html
Steeve
10-Jan-2010
[838x2]
IIRC we need UDP to do a DNS request.
So that we can't currently
Graham
10-Jan-2010
[840]
Yeah .. just did a packet trace and it's all UDP
Pekr
10-Jan-2010
[841]
R3 does not contain UDP in networking device low level code?
Steeve
10-Jan-2010
[842]
not yet
Graham
10-Jan-2010
[843x2]
Steeve, what's the algorithm for reading data from a port when you 
don't know how much data is coming down?
Does each arrival of data trigger a 'read event?