From 21e0a86f8f23675a8aa1cb8522917093ba77c490 Mon Sep 17 00:00:00 2001 From: Tassilo Schweyer Date: Sun, 30 May 2010 07:21:36 +0800 Subject: [PATCH] extend ruby test client a bit --- ruby/test_client.rb | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/ruby/test_client.rb b/ruby/test_client.rb index da30c78..049e3c7 100644 --- a/ruby/test_client.rb +++ b/ruby/test_client.rb @@ -1,18 +1,21 @@ require 'rubygems' require 'eventmachine' +require 'json' - module EchoServer - def post_init - puts "sending our hello" - send_datagram "{'+end':'0eb2ad19a7b508cc09b2d52b4a506845db39fae2'}", "telehash.org", 42424 - end +module EchoServer + def post_init + puts "sending our hello" + send_datagram({'+end'=>'0eb2ad19a7b508cc09b2d52b4a506845db39fae2'}.to_json, "telehash.org", 42424) + end + + def receive_data(data) + # parse message we received + telex=JSON.parse(data) + puts telex.inspect + end + +end - def receive_data data - puts data - end - - end - - EventMachine::run { - EventMachine::open_datagram_socket "0.0.0.0", 0, EchoServer - } \ No newline at end of file +EventMachine::run do + EventMachine::open_datagram_socket "0.0.0.0", 0, EchoServer +end