Contents

class rpc-server

Overview

This class provides a rpc server. It is initialized with a port number <port> and a login provider <_login-provider>. The login provider is a function of 3 arguments: (lambda (user pass chalenge) ...) . The login provider must determine if the given user <user> can login with the given password <pass>, given the given <chalenge>. It must return #f, if the user cannot login and a symbol indicating the autorisation context otherwise.

Example

 (require (planet "roos.scm" ("oesterholt" "roos.plt" 1 0)))
 (require "mzrpc.scm")

 ;; define an function that can becalled over rpc
 (rpc-define (plus (a number?) (b number?)) (+ a b))

 ;; define an overridden class for rpc-server.
 (def-class
   (this (my-rpc-server . args))
   (supers (apply rpc-server args))
   (private
     (define _clients (make-hash-table))
     (define (notifier c i)
       (sleep 1)
       (-> c notify-client i)
       (notifier c (+ i 1)))
    )
   (public
     (define (client-handler-started client)
       (display "client-handler-started called\n")
       (hash-table-put! _clients client (thread (lambda ()
                                                   (notifier client 0)))))

      (define (client-handler-ended client)
        (display "client-handler-ended called\n")
        (let ((t (hash-table-get _clients client)))
          (kill-thread t)))
   )
   (constructor)
  )

 ;; Define and call the server.
 (define S (my-rpc-server 4002 (lambda (user pass chalenge) 'admin)))
 (-> S run)

Public members

(add levels . rpc-functions)

Adds the given rpc-functions, which have been defined using rpc-define to this server.

(run)

Run this server. It will start handling clients.

(client-handler-started client)

This function can be overridden. It is called when a client connects with the client object that handles the client.

(client-handler-ended client)

This function can be overridden. It is called when a client disconnects with the client object that handles the client.