run-client.scm 781 B

1234567891011121314151617181920212223242526272829
  1. (use-modules ((tcp-client) #:prefix client:)
  2. (ice-9 textual-ports)
  3. (json))
  4. (define (client-json-display-message-handler in-out-sock scm-native)
  5. (display (simple-format #f "RECEIVED JSON: ~s, which is: ~s\n"
  6. scm-native
  7. (scm->json-string scm-native))))
  8. (define client-json-display-protocol
  9. (client:make-client-protocol
  10. #:port-reader json->scm
  11. #:message-handler client-json-display-message-handler
  12. #:eof-handler close))
  13. (define client-sock
  14. (client:run-client 12345
  15. #:protocol client-json-display-protocol))
  16. (scm->json '((a . 1)) client-sock)
  17. ;; To run this you need to add the containing directory to the load path.
  18. ;; (add-to-load-path "YOUR DIRECTORY HERE")