revent 0.1 → 0.2
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/lib/revent/CallEvent.as +25 -0
- data/lib/revent/Client.as +95 -0
- data/lib/revent/amf3/LICENSE +22 -0
- data/lib/revent/amf3/README +6 -0
- data/lib/revent/amf3/amf3.rb +11 -0
- data/lib/revent/amf3/app/configuration.rb +79 -0
- data/lib/revent/amf3/app/fault_object.rb +13 -0
- data/lib/revent/amf3/exception/rubyamf_exception.rb +95 -0
- data/lib/revent/amf3/io/amf_deserializer.rb +315 -0
- data/lib/revent/amf3/io/amf_serializer.rb +184 -0
- data/lib/revent/amf3/io/read_write.rb +308 -0
- data/lib/revent/amf3/util/string.rb +33 -0
- data/lib/revent/amf3/util/vo_helper.rb +121 -0
- data/lib/revent/as_r.rb +178 -0
- data/lib/revent/r_r.rb +176 -0
- data/test/as_r/Document.as +63 -0
- data/test/as_r/client.fla +0 -0
- data/test/as_r/client.swf +0 -0
- data/test/as_r/server.rb +48 -0
- data/{sample → test/r_r}/client.rb +0 -0
- data/{sample → test/r_r}/server.rb +0 -0
- metadata +31 -6
- data/lib/revent.rb +0 -166
@@ -0,0 +1,63 @@
|
|
1
|
+
package {
|
2
|
+
import flash.display.Sprite;
|
3
|
+
import revent.Client;
|
4
|
+
import revent.CallEvent;
|
5
|
+
|
6
|
+
public class Document extends Sprite {
|
7
|
+
private static const CMD1:int = 0;
|
8
|
+
private static const CMD2:int = 1;
|
9
|
+
|
10
|
+
private var _client:Client;
|
11
|
+
|
12
|
+
public function Document():void {
|
13
|
+
_client = new Client();
|
14
|
+
_client.addEventListener(CallEvent.CONNECT, onConnect);
|
15
|
+
_client.addEventListener(CallEvent.CLOSE, onClose);
|
16
|
+
_client.addEventListener(CallEvent.IO_ERROR, onIOError);
|
17
|
+
_client.addEventListener(CallEvent.SECURITY_ERROR, onSecurityError);
|
18
|
+
_client.addEventListener(CallEvent.CALL, onCall);
|
19
|
+
_client.addEventListener(CallEvent.RESULT, onResult);
|
20
|
+
_client.addEventListener(CallEvent.ERROR, onError);
|
21
|
+
_client.connect("localhost", 1935);
|
22
|
+
}
|
23
|
+
|
24
|
+
// ---------------------------------------------------------------------------
|
25
|
+
|
26
|
+
private function onConnect(event:CallEvent):void {
|
27
|
+
for (var i:int; i < 3; i++) {
|
28
|
+
_client.call(CMD1, ["1", 23, null]);
|
29
|
+
_client.call(CMD2, 99);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
private function onClose(event:CallEvent):void {
|
34
|
+
trace("onClose");
|
35
|
+
}
|
36
|
+
|
37
|
+
private function onIOError(event:CallEvent):void {
|
38
|
+
trace("onIOError");
|
39
|
+
}
|
40
|
+
|
41
|
+
private function onSecurityError(event:CallEvent):void {
|
42
|
+
trace("onSecurityError");
|
43
|
+
}
|
44
|
+
|
45
|
+
private function onCall(event:CallEvent):void {
|
46
|
+
trace("onCall");
|
47
|
+
trace(event.cmd);
|
48
|
+
trace(event.value);
|
49
|
+
}
|
50
|
+
|
51
|
+
private function onResult(event:CallEvent):void {
|
52
|
+
trace("onResult");
|
53
|
+
trace(event.cmd);
|
54
|
+
trace(event.value);
|
55
|
+
}
|
56
|
+
|
57
|
+
private function onError(event:CallEvent):void {
|
58
|
+
trace("onError");
|
59
|
+
trace(event.cmd);
|
60
|
+
trace(event.value);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
Binary file
|
Binary file
|
data/test/as_r/server.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'revent/as_r'
|
2
|
+
|
3
|
+
class Server
|
4
|
+
include Revent::ASRServer
|
5
|
+
|
6
|
+
CMD1 = 0
|
7
|
+
CMD2 = 1
|
8
|
+
|
9
|
+
def initialize(host, port)
|
10
|
+
start_server(host, port)
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_connect(client)
|
14
|
+
puts "on_connect:"
|
15
|
+
puts client.remote_ip
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_close(client)
|
19
|
+
puts "on_close:"
|
20
|
+
puts client.remote_ip
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_call(client, cmd, value)
|
24
|
+
puts "on_call:"
|
25
|
+
puts client.remote_ip
|
26
|
+
puts cmd
|
27
|
+
puts value
|
28
|
+
[cmd, value]
|
29
|
+
end
|
30
|
+
|
31
|
+
def on_result(client, cmd, value)
|
32
|
+
puts "on_result:"
|
33
|
+
puts client.remote_ip
|
34
|
+
puts cmd
|
35
|
+
puts result
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_error(client, cmd, value)
|
39
|
+
puts "on_error:"
|
40
|
+
puts client.remote_ip
|
41
|
+
puts cmd
|
42
|
+
puts error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
EventMachine::run do
|
47
|
+
Server.new("localhost", 1935)
|
48
|
+
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ngoc DAO Thanh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-09 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,11 +23,36 @@ extra_rdoc_files: []
|
|
23
23
|
|
24
24
|
files:
|
25
25
|
- test
|
26
|
-
-
|
27
|
-
-
|
28
|
-
-
|
26
|
+
- test/as_r
|
27
|
+
- test/as_r/client.fla
|
28
|
+
- test/as_r/server.rb
|
29
|
+
- test/as_r/client.swf
|
30
|
+
- test/as_r/Document.as
|
31
|
+
- test/r_r
|
32
|
+
- test/r_r/client.rb
|
33
|
+
- test/r_r/server.rb
|
29
34
|
- lib
|
30
|
-
- lib/revent
|
35
|
+
- lib/revent
|
36
|
+
- lib/revent/r_r.rb
|
37
|
+
- lib/revent/as_r.rb
|
38
|
+
- lib/revent/Client.as
|
39
|
+
- lib/revent/amf3
|
40
|
+
- lib/revent/amf3/app
|
41
|
+
- lib/revent/amf3/app/fault_object.rb
|
42
|
+
- lib/revent/amf3/app/configuration.rb
|
43
|
+
- lib/revent/amf3/LICENSE
|
44
|
+
- lib/revent/amf3/io
|
45
|
+
- lib/revent/amf3/io/amf_deserializer.rb
|
46
|
+
- lib/revent/amf3/io/read_write.rb
|
47
|
+
- lib/revent/amf3/io/amf_serializer.rb
|
48
|
+
- lib/revent/amf3/util
|
49
|
+
- lib/revent/amf3/util/vo_helper.rb
|
50
|
+
- lib/revent/amf3/util/string.rb
|
51
|
+
- lib/revent/amf3/README
|
52
|
+
- lib/revent/amf3/exception
|
53
|
+
- lib/revent/amf3/exception/rubyamf_exception.rb
|
54
|
+
- lib/revent/amf3/amf3.rb
|
55
|
+
- lib/revent/CallEvent.as
|
31
56
|
- setup.rb
|
32
57
|
- INSTALL
|
33
58
|
- README
|
data/lib/revent.rb
DELETED
@@ -1,166 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
# Included by both ReventServer and ReventClient.
|
6
|
-
module ReventCon
|
7
|
-
attr_writer :me
|
8
|
-
attr_accessor :property # Something that you want to associate with this connection
|
9
|
-
attr_writer :cons # Only used for ReventServer
|
10
|
-
|
11
|
-
def post_init
|
12
|
-
@connected = true
|
13
|
-
@data = ''
|
14
|
-
end
|
15
|
-
|
16
|
-
def receive_data(data)
|
17
|
-
@data << data
|
18
|
-
|
19
|
-
while true
|
20
|
-
io = StringIO.new(@data)
|
21
|
-
o = Marshal.load(io)
|
22
|
-
@data.slice!(0, io.pos)
|
23
|
-
process(o)
|
24
|
-
end
|
25
|
-
rescue
|
26
|
-
end
|
27
|
-
|
28
|
-
def process(o)
|
29
|
-
case o[:type]
|
30
|
-
when :call
|
31
|
-
result = @cons.nil? ? @me.on_call(o[:cmd], o[:arg]) : @me.on_call(self, o[:cmd], o[:arg])
|
32
|
-
o = {:type => :result, :cmd => o[:cmd], :result => result}
|
33
|
-
send_data(Marshal.dump(o))
|
34
|
-
when :result
|
35
|
-
@cons.nil? ? @me.on_result(o[:cmd], o[:result]) : @me.on_result(self, o[:cmd], o[:result])
|
36
|
-
when :error
|
37
|
-
@cons.nil? ? @me.on_error(o[:cmd], o[:error]) : @me.on_error(self, o[:cmd], o[:error])
|
38
|
-
end
|
39
|
-
rescue => e
|
40
|
-
o = {:type => :error, :cmd => o[:cmd], :error => e}
|
41
|
-
send_data(Marshal.dump(o))
|
42
|
-
end
|
43
|
-
|
44
|
-
def unbind
|
45
|
-
@connected = false
|
46
|
-
if @cons.nil?
|
47
|
-
@me.on_close
|
48
|
-
else
|
49
|
-
@me.on_close(self)
|
50
|
-
@cons.delete(self)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# ----------------------------------------------------------------------------
|
55
|
-
|
56
|
-
def connected?
|
57
|
-
@connected
|
58
|
-
end
|
59
|
-
|
60
|
-
# IP of the container
|
61
|
-
def remote_ip
|
62
|
-
a = get_peername[2,6].unpack("nC4")
|
63
|
-
a.delete_at(0)
|
64
|
-
a.join('.')
|
65
|
-
end
|
66
|
-
|
67
|
-
def call(cmd, arg)
|
68
|
-
o = {:type => :call, :cmd => cmd, :arg => arg}
|
69
|
-
send_data(Marshal.dump(o))
|
70
|
-
end
|
71
|
-
|
72
|
-
def close
|
73
|
-
close_connection_after_writing
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# To make your class a server, just include ReventServer in it.
|
78
|
-
module ReventServer
|
79
|
-
def start_server(host, port)
|
80
|
-
@revent_cons = []
|
81
|
-
EventMachine::start_server(host, port, ReventCon) do |con|
|
82
|
-
@revent_cons << con
|
83
|
-
con.me = self
|
84
|
-
con.cons = @revent_cons
|
85
|
-
on_connect(con)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Utilities. You can call remote_ip, call, close directly on each "client", as
|
90
|
-
# if it is an instance of ReventClient.
|
91
|
-
# ----------------------------------------------------------------------------
|
92
|
-
|
93
|
-
def clients
|
94
|
-
@revent_cons
|
95
|
-
end
|
96
|
-
|
97
|
-
def on_connect(client)
|
98
|
-
end
|
99
|
-
|
100
|
-
# ----------------------------------------------------------------------------
|
101
|
-
|
102
|
-
def on_connect(client)
|
103
|
-
end
|
104
|
-
|
105
|
-
def on_close(client)
|
106
|
-
end
|
107
|
-
|
108
|
-
def on_call(client, cmd, arg)
|
109
|
-
end
|
110
|
-
|
111
|
-
def on_result(client, cmd, result)
|
112
|
-
end
|
113
|
-
|
114
|
-
def on_error(client, cmd, error)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# To make your class a client, just include ReventClient in it.
|
119
|
-
module ReventClient
|
120
|
-
def connect(host, port)
|
121
|
-
EventMachine::connect(host, port, ReventCon) do |con|
|
122
|
-
@revent_con = con
|
123
|
-
con.me = self
|
124
|
-
on_connect
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
# Utilities ------------------------------------------------------------------
|
129
|
-
|
130
|
-
def property
|
131
|
-
@revent_con.property
|
132
|
-
end
|
133
|
-
|
134
|
-
def property=(value)
|
135
|
-
@revent_con.property = value
|
136
|
-
end
|
137
|
-
|
138
|
-
def remote_ip
|
139
|
-
@revent_con.remote_ip
|
140
|
-
end
|
141
|
-
|
142
|
-
def call(cmd, arg)
|
143
|
-
@revent_con.call(cmd, arg)
|
144
|
-
end
|
145
|
-
|
146
|
-
def close
|
147
|
-
@revent_con.close_connection_after_writing
|
148
|
-
end
|
149
|
-
|
150
|
-
# ----------------------------------------------------------------------------
|
151
|
-
|
152
|
-
def on_connect
|
153
|
-
end
|
154
|
-
|
155
|
-
def on_close
|
156
|
-
end
|
157
|
-
|
158
|
-
def on_call(cmd, arg)
|
159
|
-
end
|
160
|
-
|
161
|
-
def on_result(cmd, result)
|
162
|
-
end
|
163
|
-
|
164
|
-
def on_error(cmd, error)
|
165
|
-
end
|
166
|
-
end
|