Skip to content

Commit

Permalink
new communication protocol (should be much more reliable!), version b…
Browse files Browse the repository at this point in the history
…ump 0.2.0
  • Loading branch information
darwin committed Jun 20, 2009
1 parent 2bcb54e commit cf099dc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions lib/xrefresh-server.rb
Expand Up @@ -19,6 +19,7 @@ module XRefreshServer
VERSION = File.read(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'VERSION'))
AGENT = "OSX xrefresh-server"
CONFIG_FILE = ".xrefresh-server.yml"
XREFRESH_MESSAGE_SEPARATOR = "---XREFRESH-MESSAGE---"

def self.die(s)
$stderr.puts s
Expand Down
14 changes: 12 additions & 2 deletions lib/xrefresh-server/client.rb
Expand Up @@ -21,7 +21,7 @@ def name
def send(data)
return if @dead
begin
@socket << data.to_json
@socket << data.to_json + XREFRESH_MESSAGE_SEPARATOR
rescue
OUT.puts "Client #{name} #{red("is dead")}"
@dead = true
Expand All @@ -37,14 +37,24 @@ def send_about(version, agent)
end

def send_do_refresh(root, name, type, date, time, files)
# read all CSS files and add them into response
contents = {}
files.each do |item|
next unless item["path1"] =~ /\.css$/
path = File.join(root, item["path1"])
content = File.open(path).read
contents[item["path1"]] = content
end

send({
"command" => "DoRefresh",
"root" => root,
"name" => name,
"date" => date,
"time" => time,
"type" => type,
"files" => files
"files" => files,
"contents" => contents
})
end
end
Expand Down
21 changes: 7 additions & 14 deletions lib/xrefresh-server/server.rb
Expand Up @@ -19,25 +19,18 @@ def serve(socket)
@last_client_id += 1
client = Client.new(@last_client_id, socket)
@clients.add(client)
buffer = ""
loop do
# accumulate incomming input in @buffer
begin
buffer += socket.gets
buffer = socket.gets(XREFRESH_MESSAGE_SEPARATOR)
rescue
# socket breaks on client disconnection
break
end

begin
# try to parse buffer
msg = JSON.parse buffer
rescue
# buffer may be incomplete due to packet fragmentation ...
else
# got whole message => process it
buffer = ""
process(client, msg)
end
break unless buffer
message = buffer[0...-XREFRESH_MESSAGE_SEPARATOR.size]
OUT.puts "[debug] received: "+ message
json = JSON.parse(message)
process(client, json)
end
end

Expand Down
2 changes: 1 addition & 1 deletion rakefile
Expand Up @@ -26,7 +26,7 @@ begin
namespace :rubyforge do

desc "Release gem and RDoc documentation to RubyForge"
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
task :release => ["rubyforge:release:gem"] #, "rubyforge:release:docs"]

namespace :release do
desc "Publish RDoc to RubyForge."
Expand Down
6 changes: 3 additions & 3 deletions xrefresh-server.gemspec
Expand Up @@ -2,11 +2,11 @@

Gem::Specification.new do |s|
s.name = %q{xrefresh-server}
s.version = "0.1.5"
s.version = "0.2.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Antonin Hildebrand"]
s.date = %q{2009-05-26}
s.date = %q{2009-06-20}
s.default_executable = %q{xrefresh-server}
s.description = %q{XRefresh is browser refresh automation for web developers}
s.email = %q{antonin@hildebrand.cz}
Expand All @@ -25,7 +25,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{xrefresh-server}
s.rubygems_version = %q{1.3.3}
s.rubygems_version = %q{1.3.4}
s.summary = %q{XRefresh filesystem monitor for OSX}

if s.respond_to? :specification_version then
Expand Down

0 comments on commit cf099dc

Please sign in to comment.