]> gitweb.factorcode.org Git - factor.git/blob - extra/zeromq/examples/wuclient.factor
4f39db82d3a2ddb756e86719c6c4f986411c762d
[factor.git] / extra / zeromq / examples / wuclient.factor
1 ! Copyright (C) 2012 Eungju PARK.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: byte-arrays command-line destructors formatting io kernel
4 math math.parser namespaces sequences splitting strings zeromq
5 zeromq.ffi ;
6 IN: zeromq.examples.wuclient
7
8 : wuclient ( -- )
9     [
10         <zmq-context> &dispose
11         "Collecting updates from weather server…" print
12         ZMQ_SUB <zmq-socket> &dispose
13         dup "tcp://localhost:5556" zmq-connect
14         command-line get [ "10001 " ] [ first ] if-empty
15         2dup >byte-array ZMQ_SUBSCRIBE swap zmq-setopt
16         0 100 dup [
17             [ pick 0 zmq-recv
18               >string " " split [ string>number ] map second +
19             ] times
20         ] dip
21         / "Average temperature for zipcode '%s' was %dF\n" printf
22         drop
23     ] with-destructors ;
24
25 MAIN: wuclient
26