Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.IOErrorEvent;
- import flash.events.ProgressEvent;
- import flash.events.SecurityErrorEvent;
- import flash.net.Socket;
- import flash.utils.ByteArray;
- /**
- * ...
- * @author Samuel Walker
- */
- public class Main extends MovieClip
- {
- private var s:Socket;
- public function Main()
- {
- trace("hello");
- s = new Socket();
- s.addEventListener(Event.CONNECT, handleSocketConnect);
- s.addEventListener(Event.CLOSE, handleSocketClose);
- s.addEventListener(IOErrorEvent.IO_ERROR, socketIOErrorHandler);
- s.addEventListener(ProgressEvent.SOCKET_DATA, handleSocketData);
- s.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSocketSecurityError);
- s.connect("2607:fcc8:d48b:eb00:1053:b4fd:c1a5:6753", 2004);
- //s.connect("sfxworks.net", 80);
- }
- private function handleSocketSecurityError(e:SecurityErrorEvent):void
- {
- trace("Socket security error.");
- trace(e.errorID);
- trace(e.text);
- }
- private function handleSocketData(e:ProgressEvent):void
- {
- try
- {
- var ba:ByteArray = new ByteArray();
- trace("Progress event.");
- trace(s.readBytes(ba, 0, s.bytesAvailable));
- trace("Length:" + ba.length);
- trace("Data:" + ba.readUTFBytes(ba.length));
- ba.position = 0;
- trace("Raw:");
- for (var i:int = 0; i < ba.length; i++)
- {
- trace(ba.readByte().toString(2));
- }
- trace("Read " + ba.readUTFBytes(ba.length)
- }
- catch (e:Error)
- {
- trace("Coudlnt read in utf format.");
- }
- }
- private function socketIOErrorHandler(e:IOErrorEvent):void
- {
- trace("IOerror");
- trace(e.errorID);
- trace(e.text);
- }
- private function handleSocketClose(e:Event):void
- {
- trace("Socket close");
- }
- private function handleSocketConnect(e:Event):void
- {
- trace("socket connect.");
- s.writeUTFBytes("HELLO WARLD");
- s.flush();
- }
- }
- }
Add Comment
Please, Sign In to add comment