PHP and Flash AS3 Socket Communication transfer file implementation code, _php tutorial

Source: Internet
Author: User

PHP and Flash AS3 Socket Communication transfer file implementation code,


Some time ago in Flashseer saw someone mentioned: you can send the SWF file through the socket, so that the user cannot get to the SWF file ... There was no AS3 anti-compilation, so the protection of the program did not care. With the anti-compilation program of civilians, do not want others to see the source code friends are more anxious ...

Send SWF file via socket to avoid leaking source code (AS3 only): Let the main program's loader (foreground swf) connect to the daemon through the socket, and then request the main program file. Background read the main program data through the socket sent to the main program Loader. The 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; Import Flash.display.loader;public class Sockettest extends Sprite {public Function sockettest () {var socket = new Soc  Ket ();  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);   } 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 the data ends with end, the data transfer ends if (stringutil.endswith (str, ' end ')) {response=response.substr (0,response.length-3);   Convert 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 has data!");  Readresponse (); }  }}}

PHP:

Background Scoket program, because the application of PHP writing is relatively simple, it was 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 ' sock Et_create () Failed:reason: '. Socket_strerror ($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 ... ';d o {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);




http://www.bkjia.com/PHPjc/864935.html www.bkjia.com true http://www.bkjia.com/PHPjc/864935.html techarticle PHP and Flash AS3 Socket communication file Implementation code, some time ago in Flashseer saw someone mentioned: you can send the SWF file through the socket, so that users cannot get to the SWF file ... At that time ...

  • 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.