hprose 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/client.rb +2 -2
- data/examples/server.rb +2 -2
- data/examples/tcpclient.rb +21 -1
- data/examples/tcpserver.rb +49 -0
- data/lib/hprose/client.rb +2 -2
- data/lib/hprose/service.rb +2 -2
- data/lib/hprose/tcpserver.rb +84 -0
- data/lib/hprose.rb +3 -1
- data/lib/hproseserver.rb +4 -2
- metadata +4 -2
data/examples/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'hprose'
|
3
3
|
|
4
|
-
client = HproseClient.new('http://
|
4
|
+
client = HproseClient.new('http://127.0.0.1:3000/')
|
5
5
|
def error(name, e)
|
6
6
|
puts name
|
7
7
|
puts e
|
@@ -12,7 +12,7 @@ math = client.use_service(nil, :math)
|
|
12
12
|
|
13
13
|
client.hello('World') { |result|
|
14
14
|
puts result
|
15
|
-
}
|
15
|
+
}.join
|
16
16
|
|
17
17
|
math.add(1, 2) { |result|
|
18
18
|
puts result
|
data/examples/server.rb
CHANGED
@@ -14,7 +14,7 @@ class User
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def getUser()
|
17
|
-
return User.new
|
17
|
+
return User.new
|
18
18
|
end
|
19
19
|
|
20
20
|
|
@@ -33,7 +33,7 @@ end
|
|
33
33
|
|
34
34
|
HproseClassManager.register(User, "User")
|
35
35
|
|
36
|
-
app = HproseHttpService.new
|
36
|
+
app = HproseHttpService.new
|
37
37
|
|
38
38
|
app.add(:hello)
|
39
39
|
app.add(:sum) { |*num|
|
data/examples/tcpclient.rb
CHANGED
@@ -8,4 +8,24 @@ def error(name, e)
|
|
8
8
|
end
|
9
9
|
client.onerror = :error
|
10
10
|
|
11
|
-
|
11
|
+
math = client.use_service(nil, :math)
|
12
|
+
|
13
|
+
client.hello('World') { |result|
|
14
|
+
puts result
|
15
|
+
}.join
|
16
|
+
|
17
|
+
math.add(1, 2) { |result|
|
18
|
+
puts result
|
19
|
+
}.join
|
20
|
+
|
21
|
+
math.sub(1, 2) { |result|
|
22
|
+
puts result
|
23
|
+
}.join
|
24
|
+
|
25
|
+
puts client.sum(1,3,4,5,6,7)
|
26
|
+
user = client.getUser()
|
27
|
+
puts user.name
|
28
|
+
puts user.age
|
29
|
+
|
30
|
+
puts client.hi('hprose')
|
31
|
+
puts client.push([user, user, user])
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rack'
|
3
|
+
require 'hprose'
|
4
|
+
|
5
|
+
def hello(name)
|
6
|
+
return 'hello ' << name << '!'
|
7
|
+
end
|
8
|
+
|
9
|
+
class User
|
10
|
+
def initialize()
|
11
|
+
@name = "Tom"
|
12
|
+
@age = 28
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def getUser()
|
17
|
+
return User.new()
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
class MyService
|
22
|
+
def add(a, b)
|
23
|
+
return a + b
|
24
|
+
end
|
25
|
+
def sub(a, b)
|
26
|
+
return a - b
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def mf(name, args)
|
31
|
+
return name << " => " << HproseFormatter.serialize(args)
|
32
|
+
end
|
33
|
+
|
34
|
+
HproseClassManager.register(User, "User")
|
35
|
+
|
36
|
+
server = HproseTcpServer.new
|
37
|
+
server.port = 4321
|
38
|
+
|
39
|
+
server.add(:hello)
|
40
|
+
server.add(:sum) { |*num|
|
41
|
+
result = 0
|
42
|
+
num.each { |item| result += item }
|
43
|
+
result
|
44
|
+
}
|
45
|
+
server.add(:getUser)
|
46
|
+
server.add_missing_function(:mf)
|
47
|
+
server.add(MyService.new, :math)
|
48
|
+
server.debug = true
|
49
|
+
server.start
|
data/lib/hprose/client.rb
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
# #
|
15
15
|
# hprose client for ruby #
|
16
16
|
# #
|
17
|
-
# LastModified: Mar
|
17
|
+
# LastModified: Mar 11, 2014 #
|
18
18
|
# Author: Ma Bingyao <andot@hprose.com> #
|
19
19
|
# #
|
20
20
|
############################################################
|
@@ -119,7 +119,7 @@ module Hprose
|
|
119
119
|
end
|
120
120
|
def do_input(data, args, resultMode)
|
121
121
|
data = @filter.input_filter(data)
|
122
|
-
raise Exception.exception("Wrong Response: \r\n#{data}") if data[data.size - 1].ord != TagEnd
|
122
|
+
raise Exception.exception("Wrong Response: \r\n#{data}") if data.nil? or data.empty? or data[data.size - 1].ord != TagEnd
|
123
123
|
return data if resultMode == RawWithEndTag
|
124
124
|
return data.chop! if resultMode == Raw
|
125
125
|
stream = StringIO.new(data, 'rb')
|
data/lib/hprose/service.rb
CHANGED
@@ -14,14 +14,13 @@
|
|
14
14
|
# #
|
15
15
|
# hprose service for ruby #
|
16
16
|
# #
|
17
|
-
# LastModified: Mar
|
17
|
+
# LastModified: Mar 11, 2014 #
|
18
18
|
# Author: Ma Bingyao <andot@hprose.com> #
|
19
19
|
# #
|
20
20
|
############################################################
|
21
21
|
|
22
22
|
require "hprose/common"
|
23
23
|
require "hprose/io"
|
24
|
-
require "thread"
|
25
24
|
|
26
25
|
module Hprose
|
27
26
|
class Service
|
@@ -330,6 +329,7 @@ module Hprose
|
|
330
329
|
def handle(data, context)
|
331
330
|
begin
|
332
331
|
data = @filter.input_filter(data)
|
332
|
+
raise Exception.exception("Wrong Request: \r\n#{data}") if data.nil? or data.empty? or data[data.size - 1].ord != TagEnd
|
333
333
|
istream = StringIO.new(data, 'rb')
|
334
334
|
tag = istream.getbyte
|
335
335
|
case tag
|
@@ -0,0 +1,84 @@
|
|
1
|
+
############################################################
|
2
|
+
# #
|
3
|
+
# hprose #
|
4
|
+
# #
|
5
|
+
# Official WebSite: http://www.hprose.com/ #
|
6
|
+
# http://www.hprose.net/ #
|
7
|
+
# http://www.hprose.org/ #
|
8
|
+
# #
|
9
|
+
############################################################
|
10
|
+
|
11
|
+
############################################################
|
12
|
+
# #
|
13
|
+
# hprose/tcpserver.rb #
|
14
|
+
# #
|
15
|
+
# hprose tcp server for ruby #
|
16
|
+
# #
|
17
|
+
# LastModified: Mar 11, 2014 #
|
18
|
+
# Author: Ma Bingyao <andot@hprose.com> #
|
19
|
+
# #
|
20
|
+
############################################################
|
21
|
+
|
22
|
+
require "hprose/io"
|
23
|
+
require "hprose/service"
|
24
|
+
require "uri"
|
25
|
+
require "socket"
|
26
|
+
|
27
|
+
module Hprose
|
28
|
+
class TcpServer < Service
|
29
|
+
def initialize(uri = nil)
|
30
|
+
super()
|
31
|
+
@host = nil
|
32
|
+
@port = 0
|
33
|
+
unless uri.nil? then
|
34
|
+
u = URI.parse(uri)
|
35
|
+
@host = u.host
|
36
|
+
@port = u.port
|
37
|
+
end
|
38
|
+
@sockets = nil
|
39
|
+
end
|
40
|
+
def host
|
41
|
+
@host
|
42
|
+
end
|
43
|
+
def host=(host)
|
44
|
+
@host = host
|
45
|
+
end
|
46
|
+
def port
|
47
|
+
@port
|
48
|
+
end
|
49
|
+
def port=(port)
|
50
|
+
@port = port
|
51
|
+
end
|
52
|
+
def start
|
53
|
+
begin
|
54
|
+
@sockets = Socket.tcp_server_sockets(@host, @port)
|
55
|
+
@sockets.each do
|
56
|
+
Socket.accept_loop(@sockets) do |sock, client_addrinfo|
|
57
|
+
Thread.start do
|
58
|
+
begin
|
59
|
+
loop do
|
60
|
+
buf = sock.recv(4, 0)
|
61
|
+
n = buf[0].ord << 24 | buf[1].ord << 16 | buf[2].ord << 8 | buf[3].ord
|
62
|
+
data = handle(sock.recv(n, 0), client_addrinfo)
|
63
|
+
n = data.size
|
64
|
+
sock.send("" << (n >> 24 & 0xff) << (n >> 16 & 0xff) << (n >> 8 & 0xff) << (n & 0xff) << data, 0)
|
65
|
+
end
|
66
|
+
ensure
|
67
|
+
sock.close
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
rescue ::Interrupt => e
|
73
|
+
ensure
|
74
|
+
stop
|
75
|
+
end
|
76
|
+
end
|
77
|
+
def stop
|
78
|
+
unless @sockets.nil? then
|
79
|
+
@sockets.each {|s| s.close if !s.closed? }
|
80
|
+
@sockets = nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end # class TcpServer
|
84
|
+
end # module Hprose
|
data/lib/hprose.rb
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
# #
|
15
15
|
# hprose for ruby #
|
16
16
|
# #
|
17
|
-
# LastModified: Mar
|
17
|
+
# LastModified: Mar 11, 2014 #
|
18
18
|
# Author: Ma Bingyao <andot@hprose.com> #
|
19
19
|
# #
|
20
20
|
############################################################
|
@@ -34,6 +34,7 @@ module Hprose
|
|
34
34
|
autoload :TcpClient, 'hprose/tcpclient'
|
35
35
|
autoload :Service, 'hprose/service'
|
36
36
|
autoload :HttpService, 'hprose/httpservice'
|
37
|
+
autoload :TcpServer, 'hprose/tcpserver'
|
37
38
|
end
|
38
39
|
|
39
40
|
Object.const_set(:HproseException, Hprose.const_get(:Exception))
|
@@ -50,3 +51,4 @@ Object.const_set(:HproseHttpClient, Hprose.const_get(:HttpClient))
|
|
50
51
|
Object.const_set(:HproseTcpClient, Hprose.const_get(:TcpClient))
|
51
52
|
Object.const_set(:HproseService, Hprose.const_get(:Service))
|
52
53
|
Object.const_set(:HproseHttpService, Hprose.const_get(:HttpService))
|
54
|
+
Object.const_set(:HproseTcpServer, Hprose.const_get(:TcpServer))
|
data/lib/hproseserver.rb
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
# #
|
15
15
|
# hprose server for ruby #
|
16
16
|
# #
|
17
|
-
# LastModified:
|
17
|
+
# LastModified: Mar 11, 2014 #
|
18
18
|
# Author: Ma Bingyao <andot@hprose.com> #
|
19
19
|
# #
|
20
20
|
############################################################
|
@@ -22,7 +22,9 @@
|
|
22
22
|
module Hprose
|
23
23
|
autoload :Service, 'hprose/service'
|
24
24
|
autoload :HttpService, 'hprose/httpservice'
|
25
|
+
autoload :TcpServer, 'hprose/tcpserver'
|
25
26
|
end
|
26
27
|
|
27
28
|
Object.const_set(:HproseService, Hprose.const_get(:Service))
|
28
|
-
Object.const_set(:HproseHttpService, Hprose.const_get(:HttpService))
|
29
|
+
Object.const_set(:HproseHttpService, Hprose.const_get(:HttpService))
|
30
|
+
Object.const_set(:HproseTcpServer, Hprose.const_get(:TcpServer))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hprose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: andot@hprose.com
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- examples/client.rb
|
21
21
|
- examples/server.rb
|
22
22
|
- examples/tcpclient.rb
|
23
|
+
- examples/tcpserver.rb
|
23
24
|
- lib/hprose/client.rb
|
24
25
|
- lib/hprose/common.rb
|
25
26
|
- lib/hprose/httpclient.rb
|
@@ -27,6 +28,7 @@ files:
|
|
27
28
|
- lib/hprose/io.rb
|
28
29
|
- lib/hprose/service.rb
|
29
30
|
- lib/hprose/tcpclient.rb
|
31
|
+
- lib/hprose/tcpserver.rb
|
30
32
|
- lib/hprose.rb
|
31
33
|
- lib/hproseclient.rb
|
32
34
|
- lib/hprosecommon.rb
|