Advertisement
sfxworks

Untitled

Nov 5th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. package
  2. {
  3. import flash.display.MovieClip;
  4. import flash.events.Event;
  5. import flash.events.IOErrorEvent;
  6. import flash.events.ProgressEvent;
  7. import flash.events.SecurityErrorEvent;
  8. import flash.net.Socket;
  9. import flash.utils.ByteArray;
  10. /**
  11. * ...
  12. * @author Samuel Walker
  13. */
  14. public class Main extends MovieClip
  15. {
  16.  
  17. private var s:Socket;
  18. public function Main()
  19. {
  20. trace("hello");
  21. s = new Socket();
  22. s.addEventListener(Event.CONNECT, handleSocketConnect);
  23. s.addEventListener(Event.CLOSE, handleSocketClose);
  24. s.addEventListener(IOErrorEvent.IO_ERROR, socketIOErrorHandler);
  25. s.addEventListener(ProgressEvent.SOCKET_DATA, handleSocketData);
  26. s.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSocketSecurityError);
  27. s.connect("2607:fcc8:d48b:eb00:1053:b4fd:c1a5:6753", 2004);
  28. //s.connect("sfxworks.net", 80);
  29. }
  30.  
  31. private function handleSocketSecurityError(e:SecurityErrorEvent):void
  32. {
  33. trace("Socket security error.");
  34. trace(e.errorID);
  35. trace(e.text);
  36. }
  37.  
  38. private function handleSocketData(e:ProgressEvent):void
  39. {
  40. try
  41. {
  42. var ba:ByteArray = new ByteArray();
  43. trace("Progress event.");
  44. trace(s.readBytes(ba, 0, s.bytesAvailable));
  45. trace("Read " + ba.length);
  46. trace(ba.readUTFBytes(ba.length));
  47. ba.position = 0;
  48. trace("Raw:");
  49. for (var i:int = 0; i < ba.length; i++)
  50. {
  51. trace(ba.readByte().toString(2));
  52. }
  53.  
  54. trace("Read " + ba.readUTFBytes(ba.length)
  55. }
  56. catch (e:Error)
  57. {
  58. trace("Coudlnt read in utf format.");
  59. }
  60.  
  61. }
  62.  
  63. private function socketIOErrorHandler(e:IOErrorEvent):void
  64. {
  65. trace("IOerror");
  66. trace(e.errorID);
  67. trace(e.text);
  68. }
  69.  
  70. private function handleSocketClose(e:Event):void
  71. {
  72. trace("Socket close");
  73. }
  74.  
  75. private function handleSocketConnect(e:Event):void
  76. {
  77. trace("socket connect.");
  78.  
  79. s.writeUTFBytes("HELLO WARLD");
  80. s.flush();
  81. }
  82.  
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement