Permalink
Browse files

add connection notification

  • Loading branch information...
1 parent fc58929 commit b3e7d12865895025966a2ca5c750dd8ac09e399d @txus committed Aug 28, 2011
Showing with 17 additions and 1 deletion.
  1. +17 −1 lib/domodoro/client.rb
View
@@ -4,6 +4,14 @@ module Domodoro
class Client
class << self
+ def connected
+ @connected
+ end
+
+ def connected=(value)
+ @connected = true
+ end
+
def start(host, port='9111')
Config.load
puts "#{Time.now} - Domodoro listening on #{host}:#{port}"
@@ -13,6 +21,10 @@ def start(host, port='9111')
EM.run do
EM.connect(host, port) do |c|
c.extend EM::P::LineText2
+ def c.connection_completed
+ puts " - Connected to server!"
+ Client.connected = true
+ end
def c.receive_line(line)
case line
when /start/
@@ -26,7 +38,11 @@ def c.receive_line(line)
end
EM.add_periodic_timer(1) do
EM.next_tick do
- print_time
+ if Client.connected
+ print_time
+ else
+ puts 'Cannot connect to server. Is it running?'
+ end
end
end
end

0 comments on commit b3e7d12

Please sign in to comment.