In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

WebSocket

Get Adobe Flash player
by jthereliable 23 Apr 2011
    Embed
/**
 * 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);
        }
    }
}