Skip to content

Commit

Permalink
增加readme作为平台首页
Browse files Browse the repository at this point in the history
  • Loading branch information
charlescui committed Jan 15, 2013
1 parent 9702a5d commit 4939fae
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 41 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -29,6 +29,7 @@ gem "json"
gem 'uuid'
gem "redis"
gem 'virtus'
gem "maruku"
gem "hiredis"
gem "sinatra"
gem "better_errors"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -47,6 +47,8 @@ GEM
json (1.7.5)
macaddr (1.6.1)
systemu (~> 2.5.0)
maruku (0.6.1)
syntax (>= 1.0.0)
metaclass (0.0.1)
method_source (0.8.1)
mocha (0.10.5)
Expand Down Expand Up @@ -110,6 +112,7 @@ GEM
eventmachine
thin (>= 1.3.1)
slop (3.3.3)
syntax (1.0.0)
systemu (2.5.2)
thin (1.5.0)
daemons (>= 1.0.9)
Expand All @@ -136,6 +139,7 @@ DEPENDENCIES
jeweler (~> 1.8.4)
json
linecache19!
maruku
pry
pry-doc
rdoc (~> 3.12)
Expand Down
49 changes: 49 additions & 0 deletions README.md
@@ -0,0 +1,49 @@
# postman

这里是邮局,谢谢。

目前支持以下几种投递方式:

1. Long pull
2. Comet
3. Websocket

## Websocket模式

* 执行seed.rb
* 浏览器A打开:`http://42.121.89.18:8000/websocket?user_credentials=035c6c3040830130a6f200163e0218fd`
* 浏览器B打开:`http://42.121.89.18:8000/websocket?user_credentials=0360d0f040830130a6f200163e0218fd`
* 浏览器C打开:`http://42.121.89.18:8000/websocket?user_credentials=036322f040830130a6f200163e0218fd`
* 浏览器A的to字段设置消息接受者ID,可以设置多个ID,通过`,`分隔
* 浏览器A发送消息给to字段的接受者B和C,to字段值为`1234567890,09ngdfsd4321`,回车发送数据
* 浏览器B和C将收到A发过来的数据

A发送的数据为:

{
to : '1234567890,09ngdfsd4321',
content : 'hello world'
}

B,C接收到的数据位:

{
from : '0987654321',
content : 'hello world'
}

## Contributing to postman

* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
* Fork the project.
* Start a feature/bugfix branch.
* Commit and push until you are happy with your contribution.
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

## Copyright

Copyright (c) 2012 zheng.cuizh. See LICENSE.txt for
further details.

19 changes: 0 additions & 19 deletions README.rdoc

This file was deleted.

5 changes: 5 additions & 0 deletions TODO.md
@@ -0,0 +1,5 @@
# TODOLIST

## 计划任务及队列

## p2p隧道
35 changes: 18 additions & 17 deletions db/seed.rb
Expand Up @@ -4,25 +4,26 @@


u1 = User.new(
:id => '1234567890',
:name => "pman1",
:ttl => 60,
:private_key => "22fe394"
)
:id => '1234567890',
:name => "pman1",
:ttl => 60,
:private_key => "22fe394"
)
u2 = User.new(
:id => '0987654321',
:name => "pman2",
:ttl => 60,
:private_key => "22fe394"
)
:id => '0987654321',
:name => "pman2",
:ttl => 60,
:private_key => "22fe394"
)

u3 = User.new(
:id => '09ngdfsd4321',
:name => "pman3",
:ttl => 60,
:private_key => "22fe394"
)
:id => '09ngdfsd4321',
:name => "pman3",
:ttl => 60,
:private_key => "22fe394"
)

[u1,u2,u3].each do |u|
u.save if !u.exists
[u1,u2,u3].each do |u|
u.user_credentials
u.save if !u.exists
end
1 change: 1 addition & 0 deletions lib/postman.rb
@@ -1,6 +1,7 @@
$:.unshift File.dirname(__FILE__)

require "uuid"
require 'maruku'
require 'ostruct'
require "sinatra/base"
require "sinatra/reloader"
Expand Down
16 changes: 12 additions & 4 deletions lib/postman/app/controller/application_controller.rb
Expand Up @@ -41,18 +41,22 @@ def perb(template, options={}, locals={})
options = {:layout => (@@_layout ||= IO.read(settings.layout))}.merge options
erb(template, options, locals)
end

def read_me
@@_read_me ||= IO.read(File.join(BASEPATH,'..','README.md'))
end
end

dir = File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', '..')
BASEPATH = File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', '..')
# 设置视图文件目录
BASEVIEWPATH = "#{dir}/postman/app/view"
BASEVIEWPATH = "#{BASEPATH}/postman/app/view"
set :views, BASEVIEWPATH
set :layout, File.join(BASEVIEWPATH, 'layout.erb')

if respond_to? :public_folder
set :public_folder, "#{dir}/../public"
set :public_folder, "#{BASEPATH}/../public"
else
set :public, "#{dir}/../public"
set :public, "#{BASEPATH}/../public"
end
set :static, true

Expand All @@ -74,6 +78,10 @@ def perb(template, options={}, locals={})
error do
perb :"500", :views => BASEVIEWPATH
end

get '/' do
Maruku.new(read_me).to_html
end
end#ApplicationController
end
end
Expand Down
1 change: 0 additions & 1 deletion script/console
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby
require 'ruby-debug'
APP_PATH = File.expand_path('../..', __FILE__)
require File.join(APP_PATH, 'lib/postman')

Expand Down
62 changes: 62 additions & 0 deletions test/zmq_lb.rb
@@ -0,0 +1,62 @@
require "em-zeromq"

zmq = EM::ZeroMQ::Context.new(1)

EM.run {
req = zmq.socket(ZMQ::REQ)
req.on(:message) { |*parts|
p [:parts, parts.map(&:copy_out_string)]
}

5.times do |t|
rep = zmq.socket(ZMQ::REP)
fd = "ipc:///tmp/rep#{t}"
rep.bind(fd)
rep.on(:message) { |*parts|
p [:parts, parts.map(&:copy_out_string)]
rep.send_msg("hello from req #{t}")
}
req.connect(fd)
end

i = 0
EM.add_periodic_timer(1) {
puts "Sending 2-part message"
i += 1
req.send_msg("hello #{i}", "second part")
}
}


__END__

Sending 2-part message
[:parts, ["hello 1", "second part"]]
[:parts, ["hello from req 0"]]
Sending 2-part message
[:parts, ["hello 2", "second part"]]
[:parts, ["hello from req 1"]]
Sending 2-part message
[:parts, ["hello 3", "second part"]]
[:parts, ["hello from req 2"]]
Sending 2-part message
[:parts, ["hello 4", "second part"]]
[:parts, ["hello from req 3"]]
Sending 2-part message
[:parts, ["hello 5", "second part"]]
[:parts, ["hello from req 4"]]
Sending 2-part message
[:parts, ["hello 6", "second part"]]
[:parts, ["hello from req 0"]]
Sending 2-part message
[:parts, ["hello 7", "second part"]]
[:parts, ["hello from req 1"]]
Sending 2-part message
[:parts, ["hello 8", "second part"]]
[:parts, ["hello from req 2"]]
Sending 2-part message
[:parts, ["hello 9", "second part"]]
[:parts, ["hello from req 3"]]
Sending 2-part message
[:parts, ["hello 10", "second part"]]
[:parts, ["hello from req 4"]]

0 comments on commit 4939fae

Please sign in to comment.