Last active
September 22, 2016 10:22
-
-
Save dch/2a2d398bd3dd5e01e2ef653316f75524 to your computer and use it in GitHub Desktop.
Here's a racket version of a websocket cat. Sadly, racket doesn't produce a single distributable executable like OCaml or golang, so we have to make do with a turd-like tarball.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: clean | |
@raco exe wsc.rkt | |
@raco distribute wscat wsc | |
clean: | |
@rm -rf wsc wscat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require net/rfc6455) | |
(require net/url) | |
(require racket/cmdline) | |
(require json) | |
(require terminal-color) | |
(define ws-url | |
(command-line #:args (url) url)) | |
(define conn (ws-connect(string->url ws-url))) | |
(define (print-json text) (printf "~a\n " text)) | |
(let loop () | |
(define msg (ws-recv conn)) | |
(print-json msg) | |
(unless (eof-object? msg) (loop)) | |
(loop)) | |
; (define json #<<JSON | |
; {"host":"akai.skunkwerks.at", | |
; "service":"uptime/uptime", | |
; "state":null, | |
; "description":null, | |
; "metric":3096, | |
; "tags":["collectd"], | |
; "time":"2015-02-16T11:20:01.000Z", | |
; "ttl":20, | |
; "ds_index":"0", | |
; "ds_name":"value", | |
; "ds_type":"gauge", | |
; "type":"uptime", | |
; "plugin":"uptime"} | |
; JSON | |
; ) | |
; (define (print-json text) | |
; ((define json (string->jsexpr text)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment