revent 0.2.2 → 0.2.3

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/Client.as CHANGED
@@ -10,6 +10,7 @@
10
10
  private static const TYPE_ERROR:int = 2;
11
11
 
12
12
  private var _socket:Socket;
13
+ private var _bytes:ByteArray;
13
14
 
14
15
  public static function bytesToByteArray(bytes:Array):ByteArray {
15
16
  var ba:ByteArray = new ByteArray();
@@ -37,6 +38,8 @@
37
38
  _socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
38
39
  _socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
39
40
  _socket.addEventListener(ProgressEvent.SOCKET_DATA, onData);
41
+
42
+ _bytes = new ByteArray();
40
43
  }
41
44
 
42
45
  public function connect(host:String, port:int):void {
@@ -85,9 +88,17 @@
85
88
  }
86
89
 
87
90
  private function onData(event:ProgressEvent):void {
91
+ var b:ByteArray = new ByteArray();
92
+ _socket.readBytes(b);
93
+
94
+ // Append
95
+ _bytes.position = _bytes.length;
96
+ _bytes.writeBytes(b);
97
+ _bytes.position = 0;
98
+
88
99
  try {
89
100
  while (true) {
90
- var o:Array = _socket.readObject();
101
+ var o:Array = _bytes.readObject();
91
102
  var type:int = o[0];
92
103
  var cmd:Object = o[1];
93
104
  var value:Object = o[2];
@@ -105,6 +116,12 @@
105
116
  break;
106
117
  }
107
118
  dispatchEvent(e);
119
+
120
+ // Cleanup
121
+ if (_bytes.position == _bytes.length) {
122
+ _bytes = new ByteArray();
123
+ return;
124
+ }
108
125
  }
109
126
  } catch (e:Error) {
110
127
  }
data/lib/revent/as_r.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'eventmachine'
3
3
  require 'zlib'
4
+ require 'logger'
4
5
  require "#{File.dirname(__FILE__)}/amf3/amf3"
5
6
 
6
7
  # AS clients are not reliable. For security, we close the connection immediately
@@ -1,15 +1,23 @@
1
1
  package {
2
2
  import flash.display.Sprite;
3
+ import flash.events.MouseEvent;
4
+ import flash.utils.ByteArray;
5
+
3
6
  import revent.Client;
4
7
  import revent.CallEvent;
5
8
 
6
9
  public class Document extends Sprite {
7
- private static const CMD1:int = 0;
8
- private static const CMD2:int = 1;
10
+ private static const HOST:String = "localhost";
11
+ private static const PORT:int = 1935;
12
+
13
+ private static const CMD_TEST_BYTE_ARRAY:int = 0;
9
14
 
10
15
  private var _client:Client;
16
+ private var _size:int;
11
17
 
12
18
  public function Document():void {
19
+ _byteArrayBtn.addEventListener(MouseEvent.CLICK, onByteArrayBtnClick);
20
+
13
21
  _client = new Client();
14
22
  _client.addEventListener(CallEvent.CONNECT, onConnect);
15
23
  _client.addEventListener(CallEvent.CLOSE, onClose);
@@ -18,46 +26,57 @@
18
26
  _client.addEventListener(CallEvent.CALL, onCall);
19
27
  _client.addEventListener(CallEvent.RESULT, onResult);
20
28
  _client.addEventListener(CallEvent.ERROR, onError);
21
- _client.connect("localhost", 1935);
29
+ _client.connect(HOST, PORT);
22
30
  }
23
31
 
24
32
  // ---------------------------------------------------------------------------
25
33
 
26
34
  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
- }
35
+ _status.text += "onConnect\n";
31
36
  }
32
37
 
33
38
  private function onClose(event:CallEvent):void {
34
- trace("onClose");
39
+ _status.text += "onClose\n";
35
40
  }
36
41
 
37
42
  private function onIOError(event:CallEvent):void {
38
- trace("onIOError");
43
+ _status.text += "onIOError\n";
39
44
  }
40
45
 
41
46
  private function onSecurityError(event:CallEvent):void {
42
- trace("onSecurityError");
47
+ _status.text += "onSecurityError\n";
43
48
  }
44
49
 
45
50
  private function onCall(event:CallEvent):void {
46
- trace("onCall");
47
- trace(event.cmd);
48
- trace(event.value);
51
+ _status.text += "onCall\n";
52
+ _status.text += "cmd:" + event.cmd;
53
+ _status.text += "value:" + event.value;
49
54
  }
50
55
 
51
56
  private function onResult(event:CallEvent):void {
52
- trace("onResult");
53
- trace(event.cmd);
54
- trace(event.value);
57
+ _status.text += "onResult";
58
+ _status.text += "cmd:" + event.cmd;
59
+
60
+ var b:Array = event.value as Array;
61
+ //trace(b);
62
+ _status.text += "Received bytes: " + b.length;
63
+ _size += 1024;
64
+ _status.text += "Testing byte array with size: " + _size;
65
+ _client.call(CMD_TEST_BYTE_ARRAY, _size);
55
66
  }
56
67
 
57
68
  private function onError(event:CallEvent):void {
58
- trace("onError");
59
- trace(event.cmd);
60
- trace(event.value);
69
+ _status.text += "onError";
70
+ _status.text += "cmd: " + event.cmd;
71
+ _status.text += "value: " + event.value;
72
+ }
73
+
74
+ // ---------------------------------------------------------------------------
75
+
76
+ private function onByteArrayBtnClick(event:MouseEvent):void {
77
+ _size = 1024;
78
+ _status.text += "Testing byte array with size: " + _size;
79
+ _client.call(CMD_TEST_BYTE_ARRAY, _size);
61
80
  }
62
81
  }
63
82
  }
data/test/as_r/client.fla CHANGED
Binary file
data/test/as_r/client.swf CHANGED
Binary file
data/test/as_r/server.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require 'revent/as_r'
2
2
 
3
+ HOST = 'localhost'
4
+ PORT = 1935
5
+
3
6
  class Server
4
7
  include Revent::ASRServer
5
8
 
6
- CMD1 = 0
7
- CMD2 = 1
9
+ CMD_TEST_BYTE_ARRAY = 0
8
10
 
9
11
  def initialize(host, port)
10
12
  start_server(host, port)
@@ -21,11 +23,12 @@ class Server
21
23
  end
22
24
 
23
25
  def on_call(client, cmd, value)
24
- puts "on_call:"
25
- puts client.remote_ip
26
- puts cmd
27
- puts value
28
- [cmd, value]
26
+ puts "on_call:", cmd, value
27
+ a = []
28
+ (0...value).each do |i|
29
+ a << i
30
+ end
31
+ client.result(CMD_TEST_BYTE_ARRAY, a)
29
32
  end
30
33
 
31
34
  def on_result(client, cmd, value)
@@ -44,5 +47,5 @@ class Server
44
47
  end
45
48
 
46
49
  EventMachine::run do
47
- Server.new("localhost", 1935)
50
+ Server.new(HOST, PORT)
48
51
  end
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.2.2
4
+ version: 0.2.3
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-09 00:00:00 +09:00
12
+ date: 2008-02-17 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,10 +24,10 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - test
26
26
  - test/as_r
27
+ - test/as_r/Document.as
27
28
  - test/as_r/client.fla
28
29
  - test/as_r/server.rb
29
30
  - test/as_r/client.swf
30
- - test/as_r/Document.as
31
31
  - test/r_r
32
32
  - test/r_r/client.rb
33
33
  - test/r_r/server.rb