LAN内での別PCの場合の速度テストをいくつかやったけど、LocalConnectionを使って同じPC内で通信した場合の速度はどんなもんだろう、と思って確認してみた。
LocalConnectionTest – wonderfl build flash online
◆結果。
FPS:60の場合、2~30msecだった。
FPS:5の場合、200msec以上だった。
イベント処理の速度は結局フレームレートに依存しているよね、という話だと思う。
◆使い方。
:同じPCで、ブラウザウィンドウ2つでこのページを立ち上げる。
:sendボタンを押すと、相手側のテキストフィールドに数字がでる。この数字が、片道のミリ秒。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
package { import com.bit101.components.Label; import com.bit101.components.NumericStepper; import flash.display.Sprite; import flash.events.Event; import flash.net.SharedObject; /** * ... * @author umhr */ [SWF(width = 465, height = 465, backgroundColor = 0xEEEEEE, frameRate = 60)] public class WonderflMain extends Sprite { private var _numericStepper:NumericStepper; public function WonderflMain():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); // entry point var sharedObject:SharedObject = SharedObject.getLocal("my_data"); if (sharedObject) { var obj:Object = sharedObject.data; if (isNaN(obj.count)) { obj["count"] = 0; }else { obj["count"] ++; } } sharedObject.flush(); addChild(new LocalConnectionSenderExample("myConnection" + (obj.count) % 2)); addChild(new LocalConnectionReceiverExample("myConnection" + (obj.count + 1) % 2)); setFPSStepper(); } private function setFPSStepper():void { new Label(this, 320, 440, "FPS:"); _numericStepper = new NumericStepper(this, 350, 440, onNumericStepper); _numericStepper.minimum = 1; _numericStepper.maximum = 120; _numericStepper.value = 60; } private function onNumericStepper(event:Event):void { stage.frameRate = _numericStepper.value; } } } import flash.display.Sprite; import flash.events.MouseEvent; import flash.events.StatusEvent; import flash.net.LocalConnection; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFieldType; class LocalConnectionSenderExample extends Sprite { private var conn:LocalConnection; // UI elements private var messageLabel:TextField; private var message:TextField; private var sendBtn:Sprite; private var _connectionName:String = "myConnection"; public function LocalConnectionSenderExample(connectionName:String) { _connectionName = connectionName; buildUI(); sendBtn.addEventListener(MouseEvent.CLICK, sendMessage); conn = new LocalConnection(); conn.addEventListener(StatusEvent.STATUS, onStatus); } private function sendMessage(event:MouseEvent):void { conn.send(_connectionName, "lcHandler", message.text, new Date().time); message.text = ""; } private function onStatus(event:StatusEvent):void { switch (event.level) { case "status": //trace("LocalConnection.send() succeeded"); break; case "error": trace("LocalConnection.send() failed"); message.text = "ブラウザでこのページと同じページを開いてください。"; break; } } private function buildUI():void { const hPadding:uint = 5; // messageLabel messageLabel = new TextField(); messageLabel.x = 8; messageLabel.y = 8; messageLabel.text = "Text to send:"; messageLabel.autoSize = TextFieldAutoSize.LEFT; addChild(messageLabel); // message message = new TextField(); message.x = messageLabel.x + messageLabel.width + hPadding; message.y = 8; message.width = 300; message.height = 20; message.background = true; message.border = true; message.type = TextFieldType.INPUT; addChild(message); // sendBtn sendBtn = new Sprite(); sendBtn.x = message.x + message.width + hPadding; sendBtn.y = 8; var sendLbl:TextField = new TextField(); sendLbl.x = 1 + hPadding; sendLbl.y = 1; sendLbl.selectable = false; sendLbl.autoSize = TextFieldAutoSize.LEFT; sendLbl.text = "Send"; sendBtn.addChild(sendLbl); sendBtn.graphics.lineStyle(1); sendBtn.graphics.beginFill(0xcccccc); sendBtn.graphics.drawRoundRect(0, 0, (sendLbl.width + 2 + hPadding + hPadding), (sendLbl.height + 2), 5, 5); sendBtn.graphics.endFill(); addChild(sendBtn); } } import flash.display.Sprite; import flash.net.LocalConnection; import flash.text.TextField; class LocalConnectionReceiverExample extends Sprite { private var conn:LocalConnection; private var output:TextField; private var _connectionName:String = "myConnection"; public function LocalConnectionReceiverExample(connectionName:String) { _connectionName = connectionName; buildUI(); conn = new LocalConnection(); conn.client = this; try { conn.connect(_connectionName); } catch (error:ArgumentError) { trace("Can't connect...the connection name is already being used by another SWF"); } } public function lcHandler(msg:String, time:Number):void { output.appendText(msg +" " + String(new Date().time-Number(time)) + " msec" +"\n"); } private function buildUI():void { output = new TextField(); output.background = true; output.border = true; output.wordWrap = true; output.x = 8; output.y = 32; output.width = 420; output.height = 400; output.text = ""; addChild(output); } } |