2016-07-23 18:57:26 +00:00
|
|
|
#lang syndicate/actor
|
|
|
|
;; Simple demo of web driver. See web-demo.rkt for a more realistic example.
|
|
|
|
|
|
|
|
(require/activate syndicate/drivers/timer)
|
|
|
|
(require/activate syndicate/drivers/web)
|
|
|
|
(require net/url)
|
|
|
|
|
2017-02-15 23:18:19 +00:00
|
|
|
(spawn #:name 'server
|
2016-08-24 16:35:38 +00:00
|
|
|
(define vh (web-virtual-host "http" ? 9090))
|
2016-07-23 18:57:26 +00:00
|
|
|
|
2016-08-24 16:35:38 +00:00
|
|
|
(assert vh)
|
2016-07-23 18:57:26 +00:00
|
|
|
|
2016-08-24 16:35:38 +00:00
|
|
|
(on (web-request-incoming (id req) vh _ ("ws" ()))
|
2017-02-15 23:18:19 +00:00
|
|
|
(spawn
|
2016-08-24 16:35:38 +00:00
|
|
|
(assert (web-response-websocket id))
|
|
|
|
(stop-when (websocket-connection-closed id) (log-info "Connection dropped"))
|
|
|
|
(stop-when (websocket-message-recv id "quit") (log-info "Received quit command"))
|
|
|
|
(on (websocket-message-recv id $str)
|
|
|
|
(log-info "Got ~v" str)
|
|
|
|
(websocket-message-send! id str))))
|
2016-07-23 18:57:26 +00:00
|
|
|
|
2016-08-24 16:35:38 +00:00
|
|
|
(field [counter 0])
|
|
|
|
(on (web-request-get (id req) vh ("foo" ,$path))
|
|
|
|
(define req-num (counter))
|
|
|
|
(counter (+ (counter) 1))
|
|
|
|
(web-respond/xexpr! id
|
|
|
|
`(html
|
|
|
|
(body
|
|
|
|
(h1 "Hi there.")
|
|
|
|
(p ,(format "Your path was ~v, and this is request ~a"
|
|
|
|
path
|
|
|
|
req-num)))))))
|