-
Notifications
You must be signed in to change notification settings - Fork 1
/
Chat.scala
40 lines (29 loc) · 948 Bytes
/
Chat.scala
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
package interactive.chatsimple
import loci.language._
import loci.language.transmitter.rescala._
import loci.communicator.tcp._
import loci.serializer.upickle._
import rescala.default._
@multitier object Chat {
@peer type Server <: { type Tie <: Multiple[Client] }
@peer type Client <: { type Tie <: Single[Server] }
val message = on[Client] { Evt[String]() }
val publicMessage = on[Server] sbj { client: Remote[Client] =>
message.asLocalFromAllSeq collect {
case (remote, message) if remote != client => message
}
}
def main() = on[Client] {
publicMessage.asLocal observe println
for (line <- scala.io.Source.stdin.getLines())
message.fire(line)
}
}
object Server extends App {
multitier start new Instance[Chat.Server](
listen[Chat.Client] { TCP(43053) })
}
object Client extends App {
multitier start new Instance[Chat.Client](
connect[Chat.Server] { TCP("localhost", 43053) })
}