World: r3wp
[!Cheyenne] Discussions about the Cheyenne Web Server
older newer | first last |
Dockimbel 31-Dec-2009 [7022x4] | The current framework gives you access to client ports value, RSP session object associated with a client, RSP script execution (with 'do-task). |
Database accesses should be done in RSP scripts (because they are usually too time-consuming). | |
Btw, if you need to keep client specific data, it's quite simple. Here's an example (untested) : users: make block! 1 session-class: context [hits: 0] on-connect: func [client][ if not find users client [ repend users [client make session-class [ ]] ] ] on-message: func [client data /local ctx][ ctx: select users client ctx/hits: ctx/hits + 1 ... ] on-deconnect: func [client][ remove/part find users client 2 ] | |
sorry: on-deconnect => on-disconnect | |
Terry 31-Dec-2009 [7026] | Ideally, I guess all the socket control scripting should be done within the 'socket-app. I was thinking this would make a great proxy to a remote server for futher processing... but how to pass the arguments? |
Dockimbel 31-Dec-2009 [7027] | Futher processing can be done in RSP scripts in worker process, that's what they are meant for. If you need to connect to a third-party server, arguments passing depends on the communication protocol required. |
Terry 31-Dec-2009 [7028x2] | I think I'm lost (happens all the time). Let's say I want to poll a remote web page for screen scraping (or remote php processing) every 2 seconds, and pass that to a specific port.. I would do this from the 'socket-app, no? |
Now lets say the client hits an event on the web page, and now i want the timer to visit a different remote web page.. how would i pass that event to the timer? | |
Dockimbel 31-Dec-2009 [7030x2] | You would generate the timer events in the socket-app, pass the job to do to an RSP script, and use the /on-done handler to send the response to the client you want once the RSP script finished its work. (this will work once I fix the issue with 'do-task calls from 'on-timer events). |
The timer is just an event generator, you can't pass data to the timer. You need to store such info in a user session (a block! or object! for example). | |
Terry 31-Dec-2009 [7032] | Ah.. i figured out where Im lost! It's at the "generate a timer event", "pass the job to an RSP script" and the "use the /on-done handler" bits :) |
Dockimbel 31-Dec-2009 [7033] | :-) |
Terry 31-Dec-2009 [7034] | Once I figure this out, I'll paste a layer on top of it for noobs like me. |
Dockimbel 31-Dec-2009 [7035] | I guess it will be more clear once I make a few demo apps and write a doc for the new API. |
Terry 31-Dec-2009 [7036x2] | I started a diagram at least http://www.gliffy.com/publish/1943806/ |
Just need to fill in the arcs :) | |
Dockimbel 31-Dec-2009 [7038x3] | Both blocks in your diagram should be on the same horizontal line, the ws.rsp block should be behind, it's part of the backend while ws-test-app.r is on the frontend. |
should => should not | |
SVN r51 FEAT: /ws-apps folders are now protected from direct access. FEAT: modified socket apps source files are reloaded and used by new clients. FIX: web socket application's 'session object renamed to the more accurate 'rsp-session. FIX: 'do-task calls now supported in 'on-timer handler. FIX: scheduler issue with deleted jobs. | |
Terry 31-Dec-2009 [7041x3] | Moving right along :) |
ooh.. the diagram is looking shiny | |
Part of the confusing bit is the ws.html connects to the ws.rsp script first.. I would have thought of it as on the front end. | |
Dockimbel 31-Dec-2009 [7044] | I agree that's a bit confusing. |
Terry 31-Dec-2009 [7045] | how does /on-done work? |
Dockimbel 31-Dec-2009 [7046x3] | That comes from the way web socket's connection are initiated, it starts like a simple HTTP GET request and the server is supposed to validate that request, check access authorization if required, etc... So, to avoid duplicating work, I choose to re-use RSP framework as much as possible. The initial ws:// URL must point to a valid RSP script so that the server can check, for example, RSP session cookie for access rights. |
So, during the connection time, the target RSP script is not executed (unless you pass it a 'do-task in the 'on-connect handler). This target RSP gets associates with the opened socket until it's closed. | |
/on-done installs a callback handler (block! or function!) that gets invoked when the job sent by 'do-task to the RSP script is finished. | |
Terry 31-Dec-2009 [7049x2] | How do you pass a do-task to an rsp script? (what variables are passed?) |
must it be the initial rsp script? | |
Dockimbel 31-Dec-2009 [7051] | do-task takes a string! argument. You can pass anything you want using that value. |
Terry 31-Dec-2009 [7052] | I put that "do %test.r" in the timer without using do-task.. and it worked fine.. i guess that was blocking though? |
Dockimbel 31-Dec-2009 [7053x3] | You can also use the 'rsp-session object to permanently share values with the RSP process (to be usage carefully, see %ws-test-app.r). |
I've fixed several issues with timers, so yes probably. I still don't get why you want to "do" a script on each event... | |
to be usage => to be used | |
Terry 31-Dec-2009 [7056x3] | i was just experimenting. |
(as far as putting the "do" in the timer) | |
As for "do"ing a script with each event, I suppose the traditional way would be put all your code in the ws.app.r ... do ing was more like "include" | |
Dockimbel 31-Dec-2009 [7059] | The last revision will auto-load your socket app if you've modified it, but only new incoming connections will use it. Established connection will still use the older version. Once every client disconnects from the old version, the old app version is dropped out. |
Terry 31-Dec-2009 [7060x6] | Ok.. i'm officially digging Cheyenne's websockets |
some examples coming down the pipe | |
Here's a modified on-message from ws-test-app.r on-message: func [client data][ ;send data do-task/on-done data func [client data][ ;data: do/args %/c/cheyenne/cheyenne/test.r {one "two three"} ;doing a script passing /args data: read http://www.php.net/usage.php ;as a proxy to PHP server send/with data client ] ] | |
and the test.r script... (drop in Cheyenne's root) rebol [] x: to-block system/script/args to-string x/test | |
opps, change last line of test.r to to-string x/one | |
Here's a little demo that allows you to drag an image, and once you stop dragging, sends it's position to a .r script via a socket. The script then sends a message to another image on the page to reset it's top and left position to match the dragged image, +100 px The updated ws2.html page http://pastebin.com/m4f61ffd7 the updated ws-test-app.r http://pastebin.com/m7c39d7c6 and the test.r script is (place in the Chyenne root) rebol [] x: to-block system/script/args left: x/left + 100 top: x/top + 100 left: join left "px" top: join top "px" data: rejoin [{$('#carl2').css("top", "} top {");} {$('#carl2').css("left", "} left {");}] | |
Terry 1-Jan-2010 [7066] | Demo http://shinyrockets.com/ws2.html |
btiffin 1-Jan-2010 [7067] | Sorry Terry. The shinyrockets link leads to a godaddy parked page from here. |
Terry 1-Jan-2010 [7068x2] | cached |
Added an "easing" effect to demo | |
Graham 1-Jan-2010 [7070x2] | Alternate upgrade method .. download binary patch, read the current version, xor it, write it out as the new version .. and then the same as in your script above. |
Terry's demo http://70.68.163.178/ws2.html Doesn't work for me .. when I reach that page, it says "socket closed" Dragging the image doesn't do anything. | |
older newer | first last |