-
Notifications
You must be signed in to change notification settings - Fork 0
/
web-site-example.rkt
42 lines (37 loc) · 1.23 KB
/
web-site-example.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#lang racket
(require ffi/unsafe
(prefix-in zmq: "../zeromq/net/zmq.rkt"))
(define socket-uri "tcp://127.0.0.1:9999")
(thread
(lambda ()
(let* ([socket (zmq:socket (zmq:context 1) 'REP)])
(zmq:socket-bind! socket socket-uri)
(let listen ([listening #t])
(printf "responder-listening")
(let* ([received (zmq:socket-recv! socket)]
[received-str (bytes->string/utf-8 received)])
(printf (string-append received-str "\n"))
(zmq:socket-send!
socket
(string->bytes/utf-8 (string-append received-str " - echoed"))))
(listen #t)))))
(thread
(lambda ()
(let* ([socket (zmq:socket (zmq:context 1) 'REQ)])
(zmq:socket-bind! socket socket-uri)
(let send-request ([count 5])
(if (eq? count 0)
(printf "finishing requesting")
(begin
(printf "requester-sending")
(zmq:socket-send!
socket
(string->bytes/utf-8
(string-append
"Hello, "
(number->string count))))
(let ([res (zmq:socket-recv! socket)])
(printf (bytes->string/utf-8 res))
(send-request (- count 0)))))
(send-request 5)))))
(sleep 10)