Php and flashas3socket communication transfer file implementation code ,. Php and flashas3socket communication transfer file implementation code, some time ago in flashseer saw someone mentioned: you can use the socket method to transfer swf files, so that users cannot get swf files... At that time, php communicated with flash as3 socket to transmit the file implementation code,
Some time ago, someone mentioned in flashseer that the swf file can be transmitted through socket, so that users cannot get the swf file... At that time, there was no as3 decompilation, so I didn't care about program protection. with the popularization of the decompilation program, it would be a little anxious if I didn't want anyone else to see the source code...
The idea of transmitting swf files through socket to avoid Source code leakage (only applicable to as3): Let the loader (foreground swf) of the main program connect to the background program through socket, request the required main program file. the background reads the main program data and sends it to the loader of the main program through socket. the front-end swf is applicable to Loader. the loadBytes method displays the main program file.
The following is the test source code:
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 Socket (); socket. connect ("localhost", 5277); socket. addEventListener (Event. CLOSE, closeHandler); socket. addEventListener (Event. CONNECT, connectHandler); socket. addEventListe Ner (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 = ""; wri Teln ('bin'); socket. flush ();} function readResponse (): void {// accept data var str: String = socket. readUTFBytes (socket. bytesAvailable); response + = str; // when data ends with end, data transmission 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 (); // load from the 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:
// The scoket program in the background. it is easy to write because it is applicable to 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_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 ................ '; 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 Master Program Data $ f = fopen('main.swf ', 'r '); $ data = fread($f,filesize('main.swf '); fclose ($ f); // Convert to a 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 );
The implementation code of the file transfer through javasas3 socket. someone mentioned in flashseer some time ago that the swf file can be transferred through socket, so that users cannot obtain the swf file... At that time...