Permalink
Browse files

Added simple client/server example

  • Loading branch information...
bakkdoor committed Feb 17, 2012
1 parent 0198dba commit c75b9b359ea7a1009794a769f022c08cf383139d
Showing with 37 additions and 0 deletions.
  1. +22 −0 examples/client.fy
  2. +15 −0 examples/server.fy
View
@@ -0,0 +1,22 @@
+require: "msgpack.fy"
+
+client = MessagePack RPC Client new: "127.0.0.1" port: 9090
+val = client add: 1 to: 2
+# client prints 3:
+val println
+# server will print "foo":
+client print_this: "foo"
+
+# sending multiple request asynchronously (using futures / future sends):
+futures = (0..10) map: |i| {
+ client @ add: i to: (i * i)
+}
+
+# you can also do pure async sends, without getting a return value:
+10 times: |i| {
+ # async sends always return nil:
+ client @@ print_this: i
+}
+
+# prints: [0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110]
+futures map: @{ value } . inspect println
View
@@ -0,0 +1,15 @@
+require: "msgpack.fy"
+
+class MyHandler {
+ def add: a to: b {
+ return a + b
+ }
+
+ def print_this: str {
+ "Got: #{str inspect}" println
+ }
+}
+
+server = MessagePack RPC Server new
+server listen: "0.0.0.0" port: 9090 handler: $ MyHandler new
+server run

0 comments on commit c75b9b3

Please sign in to comment.