root/trunk/examples/workers/server_worker.rb

Revision 326, 0.7 kB (checked in by gethema..@gmail.com, 6 months ago)

check in new backgroundrb code

Line 
1 class TimeServer
2   # the data send by client would be received here
3   def receive_data(p_data)
4   end
5
6   # would be called when someone connects to the server for the
7   # first time
8   def post_init
9     add_periodic_timer(2) { say_hello_world }
10   end
11
12   # would be called when client connection is complete.
13   def connection_completed
14   end
15
16   def say_hello_world
17     send_data("Hello World\n")
18   end
19 end
20
21 # this worker is going to act like server.
22 class ServerWorker < BackgrounDRb::MetaWorker
23   set_worker_name :server_worker
24   def create(args = nil)
25     # start the server when worker starts
26     start_server("0.0.0.0",11009,TimeServer) do |client_connection|
27       client_connection.say_hello_world
28     end
29   end
30 end
31
Note: See TracBrowser for help on using the browser.