Php and flashas3socket communication and file transfer implementation code _ php skills

Source: Internet
Author: User
This article mainly introduces php and flashas3socket communication file transfer implementation code. This article includes AS3 code and PHP code. if you need it, you can refer to the following mentioned in flashseer: you can use the socket method to transfer the swf file so that you 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 );

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.