PHP and Flash AS3 Socket Communication transfer file implementation code _php skills

Source: Internet
Author: User
Tags socket

Some time ago in flashseer see someone mentioned: You can transfer the SWF file through the socket, so that users can not get the SWF file ... There was no AS3 at the time, so the protection of the program did not care. With the anti-compiler program of the civilian, do not want others to see the source code friends are more worried ...

Transfer SWF file via socket to avoid leaking source code (AS3 only): Let the main program's loader (front swf) connect to the daemon via the socket, and then request the main program file. Background read main program data sent to main program via socket Loader. Foreground SWF applies the Loader.loadbytes method to display the main program file.

The following is the source program for the test:

Package {import flash.display.Sprite; import flash.net.Socket; import flash.events.*; import flash.errors.IOError; impo

RT Flash.display.Loader;
  public class Sockettest extends Sprite {public Function sockettest () {var socket = new socket ();
  Socket.connect ("localhost", 5277);
  Socket.addeventlistener (Event.close, Closehandler);
  Socket.addeventlistener (Event.connect, Connecthandler);
  Socket.addeventlistener (Ioerrorevent.io_error, Ioerrorhandler);
  Socket.addeventlistener (Securityerrorevent.security_error, Securityerrorhandler);
  Socket.addeventlistener (Progressevent.socket_data, Socketdatahandler);

  var response:string;
   function Writeln (str:string): void {str+= "";
   try {socket.writeutfbytes (str);
   The catch (e:ioerror) {trace (e);
   }} function SendRequest (): void {trace ("SendRequest");
   Response= "";
   Writeln (' bin ');
  Socket.flush (); function Readresponse (): void {//Accept data var str:string=socket.readutfbytes (socket.bytesavailable);
   RESPONSE+=STR;
   When data ends with end, data transfer ends if (stringutil.endswith (str, ' end ')) {response=response.substr (0,response.length-3);
   Converts the string to ByteArray var ba=base64.decodetobytearray (response);
   Trace (' bytearray===== ', BA);
   var l:loader = new Loader ();
   Loaded from binary data stored in the ByteArray object.
   L.loadbytes (BA);
   Trace (l.content);
   AddChild (l);
  } function Closehandler (e:event): void {trace ("Socket closed!");
   function Connecthandler (e:event): void {trace ("Socket connected!");
  SendRequest ();
  function Ioerrorhandler (e:ioerrorevent): void {trace ("ioerror!");
  function Securityerrorhandler (e:securityerrorevent): void {trace ("securityerror!");
   function Socketdatahandler (e:progressevent): void {trace ("Socket have data!");
  Readresponse ();

 }

  }
}
}

PHP:

Background Scoket program, because the application of PHP is simpler to write, it is written in PHP.
Error_reporting (E_all);
error_reporting (0);
Set_time_limit (0);
Ob_implicit_flush ();
$address = ' localhost ';
$port = 5277; if (($sock = Socket_create (Af_inet, Sock_stream, sol_tcp)) < 0) {echo ' socket_create () Failed:reason: '. socket_stre Rror ($sock).
' \ n ';  } if ($ret = Socket_bind ($sock, $address, $port)) < 0) {echo ' Socket_bind () Failed:reason: '. Socket_strerror ($ret) .
' \ n '; } if ($ret = Socket_listen ($sock, 5)) < 0) {echo ' Socket_listen () Failed:reason: '. Socket_strerror ($ret).
' \ n ';
echo ' Connect ............  do {if ($msgsock = socket_accept ($sock)) < 0) {echo ' socket_accept () Failed:reason: '. Socket_strerror ($msgsock) .
  ' \ n ';
Break
  do {socket_recv ($msgsock, $BUF, 2048, 0);
  if ($buf = = "") {Socket_close ($msgsock);
  echo "some one quit";
  Break
  else if ($buf = = "Bin") {//Read main program Data $f = fopen (' main.swf ', ' R ');
  $data = Fread ($f, FileSize (' main.swf '));
  Fclose ($f); Convert to String//echo base64_eNcode ($data); $talkback = Base64_encode ($data). '
  End ';
}//Send Socket_send ($msgsock, $talkback, strlen ($talkback), 0);
} while (true);
Socket_close ($msgsock);
} while (true);
 Socket_close ($sock);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.