Advertisement
sfxworks

Untitled

Nov 5th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 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. }
  48. catch (e:Error)
  49. {
  50. trace("Coudlnt read in utf format.");
  51. }
  52.  
  53. }
  54.  
  55. private function socketIOErrorHandler(e:IOErrorEvent):void
  56. {
  57. trace("IOerror");
  58. trace(e.errorID);
  59. trace(e.text);
  60. }
  61.  
  62. private function handleSocketClose(e:Event):void
  63. {
  64. trace("Socket close");
  65. }
  66.  
  67. private function handleSocketConnect(e:Event):void
  68. {
  69. trace("socket connect.");
  70. s.writeUTFBytes("HELLO WARLD");
  71. s.flush();
  72. }
  73.  
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement