WebSocket
/**
* Copyright jthereliable ( http://wonderfl.net/user/jthereliable )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kgMp
*/
package {
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.net.Socket;
import flash.display.Sprite;
import flash.text.TextField;
public class WebSocketTest extends Sprite {
private var socket:Socket;
public function WebSocketTest() {
socket = new Socket();
socket.addEventListener(Event.CONNECT, socketConnectHandler);
socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
socket.connect("127.0.0.1",8010);
outputText("Starting Test");
}
private function socketConnectHandler(e:Event):void {
socket.writeUTF("test");
socket.flush();
}
private function socketDataHandler(e:ProgressEvent):void {
outputText(e.toString());
}
private var output_count:int=0;
private function outputText(text:String):void {
var out:TextField = new TextField();
out.width=stage.stageWidth;
out.y=22*output_count++;
out.text=text;
stage.addChild(out);
}
}
}