Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 35 lines (28 sloc) 0.935 kB
dcfa71c @gruggiero Samples in Scala up to Chapter 3
gruggiero authored
1 //
2 // Weather update server in Scala
3 // Binds PUB socket to tcp://*:5556
4 // Publishes random weather updates
5 //
6 // author Giovanni Ruggiero
7 // email giovanni.ruggiero@gmail.com
8
9 import java.util.Random
10 import org.zeromq.ZMQ
11
12 object wuserver {
13 def main(args : Array[String]) {
14
15 // Prepare our context and publisher
16 val context = ZMQ.context(1)
17 val publisher = context.socket(ZMQ.PUB)
18
19 publisher.bind("tcp://*:5556")
20
21 // Initialize random number generator
22 val srandom = new Random(System.currentTimeMillis())
23 while (true) {
24 // Get values that will fool the boss
25 val zipcode: Integer = srandom.nextInt(100000) + 1
26 val temperature: Integer = srandom.nextInt(215) - 80 + 1
27 val relhumidity: Integer = srandom.nextInt(50) + 10 + 1
28
29 // Send message to all subscribers
30 val update = String.format("%05d %d %d\u0000", zipcode, temperature, relhumidity);
31 publisher.send(update.getBytes(), 0)
32 }
33 }
34 }
Something went wrong with that request. Please try again.