/cl-rpc-udp

common lisp rpc over udp

Primary LanguageCommon Lisp

cl-rpc-udp

cl-rpc-udp is a rpc over udp tool.

Installation

  1. Clone to somewhere quicklisp can find, such as ~/quicklisp/local-projects
  2. Run (ql:quickload :cl-rpc-udp) in lisp repl to load it
  3. Run test with (asdf:test-system :cl-rpc-udp)

Usage

Server part

;; Make instance of server
(defparameter *server* (make-instance 'rpc-node))

;; Expose methods as service
(expose *server* "sum" (lambda (a b) (apply #'+ (list a b))))
(expose *server* "mul" (lambda (args) (reduce #'* args)))
(expose *server* "sub" (lambda (&rest args) (reduce #'- args)))
(expose *server* "test-func" (lambda (&rest args)
                               (reduce #'- args)))
(expose *server* "get-address" (lambda (&rest args)
                                 (declare (ignore args))
                                 (format nil "~a:~a" *remote-host* *remote-port*)))

;; Start server
(start *server* "127.0.0.1" 8000)

;; Stop when no need
(stop *server*)

Client part

;; Make instance of client
(defparameter *client* (make-instance 'rpc-node))

;; Start client
(start *client* "127.0.0.1"  9000)

;; Call methods of remote service
(call *client* "sum" '(10 20) "127.0.0.1" 8000)
(call *client* "mul" '((10 20 30)) "127.0.0.1" 8000)
(call *client* "sub" '(10 20 30) "127.0.0.1" 8000 :timeout 10)
(call *client* "get-address" '() "127.0.0.1" 8000)

;; stop client when no need
(stop *client*)

TODO -List

  • refactor server/client to make it symmetry
  • add test case
  • refactor encode and decode part
  • stop thread error case handle, add timeout
  • add checker when `call` called
  • consider make it async?

Author

License

Licensed under the MIT License.