World: r3wp
[!Cheyenne] Discussions about the Cheyenne Web Server
older newer | first last |
Terry 25-Dec-2009 [6740x5] | but wouldn't it just be standard on-connected , on-received protocol handlers anyway? |
it requires some kind of null event at the end of each incoming message | |
install-service [ name: 'test port-id: 3001 stop-at: "^@" | |
(that's the standard Flash EOF) | |
on-received: func [data][ theIP: client/remote-ip do %websockethandler.r ] | |
Dockimbel 25-Dec-2009 [6745] | If you're trying to ask if a gateway like Kazaaing can be built using UniServe, the answer is : sure and it will be scalable. |
Terry 25-Dec-2009 [6746x3] | I think the hard part is done already.. dealing with ws:// |
(maybe wss:// might be a little trickier :) | |
It's exciting.. i'm sending javascript back to the browser via the websocket to be eval'd.. the browser just became a killer GUI | |
Dockimbel 25-Dec-2009 [6749x2] | Important notice wrt web sockets : IIRC, all data sent on both sides have to be UTF-8 encoded. The current Cheyenne implementation doesn't enforce that encoding, so it's up to the developer to send the right data format. |
This is apply to the so-called "text frames" which Cheyenne supports. The other kind of frames (binary frames) doesn't require such encoding (not supported by Cheyenne yet). | |
Terry 25-Dec-2009 [6751] | UTF-8 support is icing on the cake. |
Dockimbel 25-Dec-2009 [6752] | This is apply => This applies |
Terry 25-Dec-2009 [6753x3] | Here's quick demo of pushing javascript back for eval ---------WS.html-------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Welcome!</title> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'</script> <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js'</script> </head> <body> <center> <h2>Web Socket test page</h2> <script> var conn = new WebSocket("ws://localhost/ws.rsp") conn.onopen = function(evt) { alert("Conn opened"); } conn.onmessage = function(evt) { eval(evt.data); } conn.onclose = function(evt) { alert("Conn closed"); } </script> <button onClick="conn.send('Hello World');"> Send Message </button> <button onclick="conn.send('makedrag');"> Make it drag</button> </center> <div id="test" style="height:100px;width:100px;border: 1px solid grey">MAKE ME DRAGGABLE</div> </body> </html> -------WS.rsp------ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Welcome!</title> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'</script> <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js'</script> </head> <body> <center> <h2>Web Socket test page</h2> <script> var conn = new WebSocket("ws://localhost/ws.rsp") conn.onopen = function(evt) { alert("Conn opened"); } conn.onmessage = function(evt) { eval(evt.data); } conn.onclose = function(evt) { alert("Conn closed"); } </script> <button onClick="conn.send('Hello World');"> Send Message </button> <button onclick="conn.send('makedrag');"> Make it drag</button> </center> <div id="test" style="height:100px;width:100px;border: 1px solid grey">MAKE ME DRAGGABLE</div> </body> </html> |
oops | |
WS.rsp should look like this <% ;-- RSP API web sockets specific changes -- ; ; request/web-socket? => true if this is an incoming socket message, false if it's HTTP. ; request/content/data => contains the socket message (string!) ;-- just echo back the message //prin request/content/data inc: request/content/data if inc = "makedrag" [prin "$('#test').draggable();"] if inc = "Hello World" [prin "alert('Hello back');"] %> | |
Dockimbel 25-Dec-2009 [6756x2] | Btw, the Internet Draft defining the web socket protocol (http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-54) is really badly written. In particular, algorithm descriptions are incredibly obfuscated. On the design side, a packet-oriented protocol not sending packet length (for text frames), rather relying on begin/end markers, is a surprizing choice to me. |
Terry: I'm glad you're enjoying your christmas gift. ;-) | |
Terry 25-Dec-2009 [6758x2] | yeah.. you've ruined my whole day :) |
is there a particular code snippet repository everyone is using? | |
Dockimbel 25-Dec-2009 [6760] | I guess that can use a Cheyenne powered service for that : http://www.qwikitxt.com If it doesn't suit your needs, there's http://pastebin.com/ |
Terry 25-Dec-2009 [6761] | Hey.. i like the "eat your own dogfood" philosophy |
Graham 25-Dec-2009 [6762x3] | Not using the default config .. but I get this 26/12-10:17:23.838-[RSP] ##RSP Script Error: URL = /ws.rsp File = www/ws.rsp ** Script Error : Invalid path value: data ** Where: rsp-script ** Near: [prin request/content/data] Request = make object! [ headers: [Host "localhost:8000" Connection "keep-alive" User-Agent {Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.43 Safari/532.5} Accept {application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5} Accept-Encoding "gzip,deflate" Accept-Language "en-GB,en-US;q=0.8,en;q=0.6" Accept-Charset "ISO-8859-1,utf-8;q=0.7,*;q=0.3"] status-line: #{474554202F77732E72737020485454502F312E310D0A} method: 'GET url: "/ws.rsp" content: none path: "/" target: "ws.rsp" arg: none ext: '.rsp version: none file: %www/ws.rsp script-name: none ws?: none ] |
listening on port 8000 | |
I'll download a fresh svn .. | |
Terry 25-Dec-2009 [6765] | The only problem with eating your own dog food is sometimes it just doesn't taste that good.. like when it processes html Here's the pastebin code for the eval demo above http://pastebin.com/d1cfec7dc |
Graham 25-Dec-2009 [6766] | Very odd .. downloaded fresh checkout. There's no listen in the httpd.cfg but it starts up listening at 8000 and not 80. |
Pekr 25-Dec-2009 [6767] | I think it might be somewhere in Uniserve's config ... |
Graham 25-Dec-2009 [6768] | And if i browse to http://localhost:8000/ws.html .. I see the web socket test page, and I get a Chrome alert saying that Conn closed. |
Dockimbel 25-Dec-2009 [6769] | Graham: how do you start Cheyenne? |
Graham 25-Dec-2009 [6770x3] | I don't think we can listen at 80 anyway on Windows 7 |
do %cheyenne.r | |
we can't listen .. | |
Dockimbel 25-Dec-2009 [6773] | Even if you use "Run as administrator" on REBOL binary? |
Graham 25-Dec-2009 [6774] | I created a listen on 8010 and still same error |
Dockimbel 25-Dec-2009 [6775x2] | If you're not running on port 80, you need to add the port number to the ws:// URL in ws.html. Tested here, it fixes the "conn closed" issue. |
var conn = new WebSocket("ws://localhost:8000/ws.rsp") | |
Graham 25-Dec-2009 [6777x2] | oh ... |
makes sense | |
Dockimbel 25-Dec-2009 [6779] | Terry: after taking the time to think about your comments regarding how web sockets should be integrated in UniServe & task-master, it starts to make sense and it inspires me on how it could be done and how the framework could look like. I'm writing a few specs on paper and will maybe implement a prototype tomorrow. This web sockets stuff is really going to be exiting after all. ;-) |
Terry 25-Dec-2009 [6780x3] | Yay! |
I was looking at my old experiments.. and they date back to the pre Cheyenne, Uniserve days. I simply created a traditional tcp socket to handle the tcp stuff, and Uniserve's http.r prot for http. | |
<snip> EOM: "\n" ; prints messages to console. verbose: false ; opens port io-port: open/no-wait tcp://:7001 clients: [] ; numbers of clients nc: 0 ; max clients limit mc: 50 ..... forever [ ;Events are periodical functions.. checking if a website is still up etc. Add a wait state to prevent excessive CPU usage ;wait .02 ;if not empty? %events.txt [do load %events.txt] either none? (wait [ .01 io-port]) [ clients: head clients ] [ print "a user is connecting" either ( nc < mc ) [ append clients make object! [ port: first io-port ] nc: nc + 1 respond rejoin ["Connected to ROCKSTaR" EOM ] ... etc | |
Dockimbel 25-Dec-2009 [6783] | My goal is to be able to write the server side of a web app like this one (2k concurrent users on average) http://www.onlinegames.com/basketball/ using Cheyenne & a web sockets framework with minimal efforts and good scalability. |
Terry 25-Dec-2009 [6784x3] | Yeah, was playing that.. I suck. |
On the design side, a packet-oriented protocol not sending packet length (for text frames), rather relying on begin/end markers, is a surprizing choice to me. I think this is pretty much standard.. From an Xml sockets in Flash article send() - This method allows you to send a string of characters through the socket connection. While the string is usually in XML format it does not have to be. This string can either be constructed using the XML object within Flash, or manually if size permits. Flash will also automatically append the terminating null character for you. | |
Im guessing null with websockets as 0xFF ? | |
Janko 25-Dec-2009 [6787] | uh , I just wrote a long reply here but it got eaten by the altme... in short: I was away for few days. Thanks a lot for all the comments and good info above!! Doc solved the problem also! About websocket.. wow wow wowoww!!! this will be very very cool to have!! I have made chat via chat server -> flash -> js before and COMET is a total mess and hack on the client side (it's a miracle they made it work, so many tricks in there to work) |
Kaj 25-Dec-2009 [6788x2] | The problem with markers is that you can't have the marker appearing in the data, so you have to check all data for it and escape it when found |
It's much more efficient when you can tell the size of the data in advance | |
older newer | first last |