5 ;;; 8sync --- Asynchronous programming for Guile
6 ;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
8 ;;; This file is part of 8sync.
10 ;;; 8sync is free software: you can redistribute it and/or modify it
11 ;;; under the terms of the GNU Lesser General Public License as
12 ;;; published by the Free Software Foundation, either version 3 of the
13 ;;; License, or (at your option) any later version.
15 ;;; 8sync is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU Lesser General Public License for more details.
20 ;;; You should have received a copy of the GNU Lesser General Public
21 ;;; License along with 8sync. If not, see <http://www.gnu.org/licenses/>.
23 (define-module (8s-server)
24 #:use-module (oop goops)
26 #:use-module (8sync systems web)
27 #:use-module (8sync systems websocket client)
28 #:use-module (8sync systems websocket server)
31 (define %server-port 1236)
33 (define-actor <sleeper> (<actor>)
34 ((*init* sleeper-loop))
35 (sleep-secs #:init-value 3 #:getter sleeper-sleep-secs))
37 (define (sleeper-loop actor message)
38 (while (actor-alive? actor)
39 (display "Zzzzzzzz....\n")
41 (8sleep (sleeper-sleep-secs actor))))
44 (let* ((hive (make-hive))
45 (sleeper (bootstrap-actor hive <sleeper>))
46 (server (bootstrap-actor
47 hive <websocket-server>
51 (format (current-error-port) "on-ws-connection: ws=~s\n" ws)
55 (format (current-error-port) "on-close: ~s\n" ws)))
58 (format (current-error-port) "on-error: ~s, ~s\n" ws e)))
59 (set! (.on-message ws)
61 (format (current-error-port) "on-message: ~s\n" msg)))
64 (format (current-error-port) "on-open: ~s\n" ws)))))
65 #:on-ws-close (lambda (ws)
66 (format (current-error-port) "on-close: ~s\n" ws))
67 #:on-ws-error (lambda (ws e)
68 (format (current-error-port) "on-error: ~s: ~s\n" ws e))
69 #:on-ws-message (lambda (ws msg)
70 (format (current-error-port) "on-message: ~s: ~s\n" ws msg))
71 #:on-ws-open (lambda (ws)
72 (format (current-error-port) "on-open: ~s\n" ws)))))
73 (format (current-error-port) "listening: ~s\n" %server-port)