rawjsonrpc 0.1.5 → 0.1.6
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/README.rdoc +8 -18
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/examples/server_examples.rb +38 -0
- data/lib/rawjsonrpc/server.rb +6 -41
- data/rawjsonrpc-0.1.5.gem +0 -0
- data/rawjsonrpc.gemspec +5 -3
- metadata +10 -9
data/README.rdoc
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
= rawjsonrpc
|
2
2
|
|
3
3
|
rawjsonrpc is a libary to create a jsonrpc client for every type of stream. It
|
4
|
-
also profides
|
5
|
-
based on gserver from the ruby stdlib.
|
4
|
+
also profides an server and client over tcpip.
|
6
5
|
This is libary is a my first try in ruby to create a gem. Its more a test how
|
7
6
|
gems work but i hope i can help somebody with this lib.
|
8
7
|
|
@@ -28,27 +27,18 @@ Create a client to send rpc calls.
|
|
28
27
|
client.notification("noti", 1, "t") #send notifaction no return value
|
29
28
|
client.close()
|
30
29
|
|
31
|
-
== Use
|
30
|
+
== Use the TCP server
|
32
31
|
|
33
|
-
Use the
|
32
|
+
Use the gserver to serve data over tcp ip
|
34
33
|
|
35
|
-
server = RawJsonRpc::
|
36
|
-
server.add_method("func1", method("do_stuff1")) # adds do_stuff1 as
|
37
|
-
"func1"
|
34
|
+
server = RawJsonRpc::JSONTCPServer.new(8080)
|
35
|
+
server.add_method("func1", method("do_stuff1")) # adds do_stuff1 as "func1"
|
38
36
|
server.add_method("foo", method(:bar)) # adds bar as foo
|
39
|
-
server.add_block("func2"){|a,b, *c| # adds a block with 2
|
40
|
-
args
|
37
|
+
server.add_block("func2"){|a,b, *c| # adds a block with 2 args
|
41
38
|
#do stuff # and args as func2
|
42
39
|
}
|
43
|
-
server.
|
44
|
-
|
45
|
-
== use gserver TCP
|
46
|
-
|
47
|
-
Lock in the stdlib for usage. The server delivers automaticly the functions.
|
48
|
-
Beware of adding methods or blocks after starting.
|
49
|
-
|
50
|
-
|
51
|
-
server = RawJsonRpc::TCPServer.new(#args)
|
40
|
+
server.start
|
41
|
+
server.join
|
52
42
|
|
53
43
|
== implement your own jsonclient
|
54
44
|
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
|
|
18
18
|
gem.homepage = "http://github.com/schroeder-/rawjsonrpc"
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{A basic libary for json rpc that allow to create for your stream type. It includes a TCPIp Server and Client.}
|
21
|
-
gem.description = %Q{A basic libary for json rpc that allow you to easly create one for your streamtype. It includes tcp json rpc on socket connections.
|
21
|
+
gem.description = %Q{A basic libary for json rpc that allow you to easly create one for your streamtype. It includes tcp json rpc on socket connections.}
|
22
22
|
gem.email = "midix01@googlemail.com"
|
23
23
|
gem.authors = ["Alexander Schrode"]
|
24
24
|
# dependencies defined in Gemfile
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rawjsonrpc'
|
2
|
+
|
3
|
+
|
4
|
+
def test1(a)
|
5
|
+
a
|
6
|
+
end
|
7
|
+
|
8
|
+
def test2(b,c)
|
9
|
+
b
|
10
|
+
end
|
11
|
+
|
12
|
+
def test3
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
class Tester
|
17
|
+
def b
|
18
|
+
5
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
#create exampel class
|
24
|
+
test_class = Tester.new
|
25
|
+
|
26
|
+
#launch a Server based on Gserver see infos at stdlib doc
|
27
|
+
|
28
|
+
serve1 = RawJsonRpc::JSONTCPServer.new(port=8080, maxConnections=2)
|
29
|
+
serve1.add_method("test1", method(:test1))
|
30
|
+
serve1.add_method("func2", method(:test2))
|
31
|
+
serve1.add_method("tes", method(:test3))
|
32
|
+
serve1.add_method("clas-t2", test_class.method(:b))
|
33
|
+
serve1.add_block("func4"){
|
34
|
+
return 100
|
35
|
+
}
|
36
|
+
serve1.start
|
37
|
+
serve1.join
|
38
|
+
puts "Ended"
|
data/lib/rawjsonrpc/server.rb
CHANGED
@@ -7,7 +7,6 @@
|
|
7
7
|
# This is free software. Please see the LICENSE and COPYING files for details.
|
8
8
|
|
9
9
|
require 'socket'
|
10
|
-
#require 'logger'
|
11
10
|
require 'json'
|
12
11
|
require 'gserver'
|
13
12
|
require_relative 'error'
|
@@ -70,49 +69,15 @@ module RawJsonRpc
|
|
70
69
|
end
|
71
70
|
end
|
72
71
|
end
|
73
|
-
# Implements RawServerJsonRpcBase for a TCPServer, that can only handle
|
74
|
-
# one client at once.
|
75
|
-
class ServerSocket
|
76
|
-
include RawServerJsonRpc
|
77
|
-
# sets the port for serving. Optimal you can add a logger object to log
|
78
|
-
# server activities.
|
79
|
-
def initialize(port)
|
80
|
-
@port = port
|
81
|
-
end
|
82
|
-
|
83
|
-
public
|
84
|
-
# Starts the servering the methods for clients
|
85
|
-
def serve
|
86
|
-
ser = TCPServer.new(@port)
|
87
|
-
client = ser.accept
|
88
|
-
loop do
|
89
|
-
begin
|
90
|
-
data = client.gets
|
91
|
-
if data == nil or data == "END\n"
|
92
|
-
client.close
|
93
|
-
client = server.accept
|
94
|
-
next
|
95
|
-
end
|
96
|
-
data = execute(data)
|
97
|
-
if data != nil
|
98
|
-
client.puts(data)
|
99
|
-
end
|
100
|
-
rescue SocketError
|
101
|
-
client.close
|
102
|
-
client = server.accept
|
103
|
-
# Exception from get killed
|
104
|
-
rescue Errno::EPIPE
|
105
|
-
exit
|
106
|
-
rescue => ex
|
107
|
-
client.close
|
108
|
-
raise ex
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
72
|
# Implements the RawServerJsonRpcBase as GServer the stdlib SocketServer. For
|
114
73
|
# more information go one to the stdlib.
|
115
74
|
class JSONTCPServer < GServer
|
116
75
|
include RawServerJsonRpc
|
76
|
+
def serve(io)
|
77
|
+
loop do
|
78
|
+
data = io.gets
|
79
|
+
io.puts execute(data)
|
80
|
+
end
|
81
|
+
end
|
117
82
|
end
|
118
83
|
end
|
Binary file
|
data/rawjsonrpc.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rawjsonrpc"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexander Schrode"]
|
12
|
-
s.date = "2012-01-
|
13
|
-
s.description = "A basic libary for json rpc that allow you to easly create one for your streamtype. It includes tcp json rpc on socket connections.
|
12
|
+
s.date = "2012-01-14"
|
13
|
+
s.description = "A basic libary for json rpc that allow you to easly create one for your streamtype. It includes tcp json rpc on socket connections."
|
14
14
|
s.email = "midix01@googlemail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
@@ -63,6 +63,7 @@ Gem::Specification.new do |s|
|
|
63
63
|
"doc/rdoc/lib/rawjsonrpc/server_rb.html",
|
64
64
|
"doc/rdoc/lib/rawjsonrpc_rb.html",
|
65
65
|
"doc/rdoc/rdoc.css",
|
66
|
+
"examples/server_examples.rb",
|
66
67
|
"lib/rawjsonrpc.rb",
|
67
68
|
"lib/rawjsonrpc/client.rb",
|
68
69
|
"lib/rawjsonrpc/error.rb",
|
@@ -71,6 +72,7 @@ Gem::Specification.new do |s|
|
|
71
72
|
"rawjsonrpc-0.1.2.gem",
|
72
73
|
"rawjsonrpc-0.1.3.gem",
|
73
74
|
"rawjsonrpc-0.1.4.gem",
|
75
|
+
"rawjsonrpc-0.1.5.gem",
|
74
76
|
"rawjsonrpc.gemspec",
|
75
77
|
"test/helper.rb",
|
76
78
|
"test/test_rawjsonrpc.rb"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rawjsonrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &81688840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *81688840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jeweler
|
27
|
-
requirement: &
|
27
|
+
requirement: &81688560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,9 @@ dependencies:
|
|
32
32
|
version: 1.6.4
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *81688560
|
36
36
|
description: A basic libary for json rpc that allow you to easly create one for your
|
37
|
-
streamtype. It includes tcp json rpc on socket connections.
|
38
|
-
server, one for multiple clients server based on gserver are served and a TCP client.
|
37
|
+
streamtype. It includes tcp json rpc on socket connections.
|
39
38
|
email: midix01@googlemail.com
|
40
39
|
executables: []
|
41
40
|
extensions: []
|
@@ -89,6 +88,7 @@ files:
|
|
89
88
|
- doc/rdoc/lib/rawjsonrpc/server_rb.html
|
90
89
|
- doc/rdoc/lib/rawjsonrpc_rb.html
|
91
90
|
- doc/rdoc/rdoc.css
|
91
|
+
- examples/server_examples.rb
|
92
92
|
- lib/rawjsonrpc.rb
|
93
93
|
- lib/rawjsonrpc/client.rb
|
94
94
|
- lib/rawjsonrpc/error.rb
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- rawjsonrpc-0.1.2.gem
|
98
98
|
- rawjsonrpc-0.1.3.gem
|
99
99
|
- rawjsonrpc-0.1.4.gem
|
100
|
+
- rawjsonrpc-0.1.5.gem
|
100
101
|
- rawjsonrpc.gemspec
|
101
102
|
- test/helper.rb
|
102
103
|
- test/test_rawjsonrpc.rb
|
@@ -115,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
116
|
version: '0'
|
116
117
|
segments:
|
117
118
|
- 0
|
118
|
-
hash: -
|
119
|
+
hash: -753691871
|
119
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
121
|
none: false
|
121
122
|
requirements:
|