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

World: r3wp

[!REBOL3 Schemes] Implementors guide

Graham
21-Feb-2010
[2063]
So we now have two DevBases ?
BrianH
21-Feb-2010
[2064x2]
Technically, the one accessed through CHAT is the third DevBase. 
The other two have been retired.
The first was written by Carl to do /View development, way back when, 
and never released (afaict). DevBase 2 was derived from that, and 
DevBase 3 was based on the lessons learned from 2.
Graham
21-Feb-2010
[2066]
Ok, we need to be more explicit and refer to DevBase3 now
BrianH
21-Feb-2010
[2067x5]
It's the only DevBase now. I just use the term to distinguish from 
CHAT, which is only a mezzanine that calls a DevBase client. Most 
people just call it chat.
So we have the datastore (DevBase), the server (DevBase server), 
a client (DevBase client) and the mezzanine wrapper (CHAT).
For most people those distinctions don't matter, they can just call 
it chat. It matters to me because writing another DevBase client 
is on my immediate todo list.
I client for R2, to be accessed through a CHAT mezzanine in R2.
I -> A
Graham
24-Apr-2010
[2072]
Updated Feb 21 http://github.com/gchiu/Rebol3/tree/master/protocols/
Brock
25-Apr-2010
[2073]
thanks for this Graham
DideC
26-May-2010
[2074x4]
I want to build a very very very simple web server in R3.

I just want to be able to receive an HTTP request and send the response.
But me and Rebol networking are two differents people !!


To begin, I just want to be able to display the full request in the 
response page.

So far I have wrote this by peeking code in DocBase, but it does 
not work as I want : the browser stay awaiting the answer. Can one 
point me to what's wrong ?
REBOL []

print "Serving port 8080..."

open-subport: func [port] [
    print "=== Creating sub-port"
    port/awake: func [event /local port] [
        print ["=== Subport event:" event/type]
        port: event/port
        switch/default event/type [
            read [
                print ["    " data: to-string port/data]

                write port to-binary rejoin ["<html><head></head><body>" data "</body></html>" 
                newline]
                true
            ]
            wrote [read port]
            close [close port]
        ] [false]
    ]
]

server: open tcp://:8080

server/awake: func [event] [
    print ["*** Server event:" event/type]
    if event/type = 'accept [
        open-subport first event/port
    ]
    false
]

wait 30
close server
print "Done serving"
halt
Seems I have found my way to make it working :
REBOL []

print "Serving port 8080..."

open-subport: func [port] [
	print "=== Creating sub-port"
	port/awake: func [event /local port data] [
		print ["=== Subport event:" event/type]
		port: event/port
		switch/default event/type [
			read [
				print ["    " data: to-string port/data]
				data: replace/all data newline <br>

    write port to-binary rejoin ["HTTP/1.0 200 OK^/Content-type: text/html^/^/<html><head></head><body>" 
    data "</body></html>" newline]
			]
			wrote [
				close port
			]
		] [false]
	]
	
	read port
]

server: open tcp://:8080

server/awake: func [event] [
    print ["*** Server event:" event/type]
    if event/type = 'accept [
        open-subport first event/port
    ]
    false
]

wait 30
close server
print "Done serving"
halt
NickA
26-May-2010
[2078]
great!
Andreas
26-May-2010
[2079]
You might also want to have a look at: http://github.com/earl/rebol3/blob/master/scripts/shttpd.r
Anton
27-May-2010
[2080]
Ah, you just forgot the http header.
DideC
27-May-2010
[2081]
Thank's Anton. Can be of some help.
Anton
28-May-2010
[2082]
(DideC meant to thank Andreas.)
NickA
28-May-2010
[2083]
I'm very happy to see this being done with R3 :)
Graham
28-Jun-2010
[2084x2]
Not sure what's happening here .. but my server closes the connection, 
and termintes the thread, but R3 is not getting a close event.
Hmm...but I get a close event if the server throws an exception
Graham
29-Jun-2010
[2086x2]
db: open jdbcbridge://localhost

  insert db [{select * from staff where fullname = (?)} "Graham Chiu" 
  ]
		>> print length? db 
		1
		result: pick db 1
		>> print length? db
		0
		close db
		db: open jdbcbridge://localhost:8000
		insert db {select first 2 * from staff}
		>> print length? result
		2
		>> result: copy db
		>> print length? result
		0
		close db
http://github.com/gchiu/Rebol3/blob/master/protocols/prot-jdbcbridge.r
Steeve
29-Jun-2010
[2088x2]
I see no evidence in that test. What is the events trace ?
There are potentially several problems in that code.

First, never use wait in the event handler. it's a good way to produce 
a stack overflow.
Second, I have to go to work, sorry...
Graham
29-Jun-2010
[2090]
It's so long since I looked at this R3 network stuff ...
Steeve
29-Jun-2010
[2091]
Last but not least , there is problem in the close event.

>>client/spec/data: load enline to-string client/spec/data
should probably be
>>client/spec/data: load enline to-string client/data
Graham
29-Jun-2010
[2092x9]
except I'm copying the data from client/data to client/spec/data 
...
and then clearing the client/data
I've setup a server at www.compkarori.co.nz:8020 to help debug the 
jdbcbridge protocol.
you don't need any db drivers installed on your side ... it's a tcp 
connection to the db server.
Oh yeah ... don't wipe the Db ... but I've made a backup anyway. 
 It's the demo employee.fdb that comes with firebird.
You can do this

db: open jdbcbridge://www.compkarori.co.nz:8020
insert db {select first 3 * from employee}
result: copy db
Ok, updated the protocol to remove the waits inside the handler ... 
and it is working now.  I can now detect the close event from the 
server.
Still don't know if I can reuse the port after the server closes 
it .. or, whether i need to create a new subport
going to think on the syntax to get the database metadata ... as 
I should be able to get column names, and types
Anyone tried this out?
Graham
3-Jul-2010
[2101]
What's the best way to determine whether the server has completed 
sending data if the server does not close the port?
Steeve
3-Jul-2010
[2102]
like for any protocol, the server must send the length of the data 
at first
Graham
3-Jul-2010
[2103x4]
pop uses .crlf
ftp closes the data port
http uses a content-length ...
I guess I should try that ... sending a length
pop uses crlf.crlf  .. sorry
Pavel
12-Aug-2010
[2107]
Any simple protocol example available, something like the R2 one 
long time on rebolforces, but for R3? I'd like to implement protocol 
above 'file schema. Any help/hint welcome.
Graham
12-Aug-2010
[2108]
Yes, check my github site
Pavel
12-Aug-2010
[2109x3]
I've looked at your shemes already, but all of the are network related. 
Some easy pedagogical example would help me :) how to ommit port 
numbers (maybe they are not neccesary) and especially how to manage 
subport in 'file. Anyway impressive bunch of schemes.
typo all of them
may the sheme be asynchrnous alhough file scheme is synchronous (I 
presume)?
Henrik
12-Aug-2010
[2112]
Robert made an overview of how ports work a while ago. I'm not sure 
if it's available publicly.