Home > Backend Development > PHP Tutorial > PHP and flash as3 socket communication transfer file implementation code, _PHP tutorial

PHP and flash as3 socket communication transfer file implementation code, _PHP tutorial

WBOY
Release: 2016-07-13 10:20:43
Original
846 people have browsed it

PHP and flash as3 socket communication transfer file implementation code,

Some time ago, I saw someone mention on flashseer: SWF files can be transmitted through sockets, so that users cannot obtain the SWF files... At that time, AS3 decompilation had not yet been released, so I did not care about the protection of the program. With the decompilation As the program becomes more accessible to the masses, friends who don’t want others to see the source code will be more anxious...

The idea of ​​transmitting swf files through socket to avoid leaking source code (only applicable to as3): Let the loader of the main program (front-end swf) connect to the background program through the socket, and then request the required main program file. Read the main program in the background The program data is sent to the loader of the main program through the socket. The front-end 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 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);
   } catch (e:IOError) {
   trace(e);
   }
  }
  function sendRequest():void {
   trace("sendRequest");
   response="";
   writeln('bin');
   socket.flush();
  }
  function readResponse():void {
   //接受数据
   var str:String=socket.readUTFBytes(socket.bytesAvailable);
   response+=str;
   //当数据以end结束的时候,数据传输结束
   if (StringUtil.endsWith(str,'end')) {
   response=response.substr(0,response.length-3);
   //把字符串转换为ByteArray
   var ba=Base64.decodeToByteArray(response);
   //trace('bytearray=====',ba);
   var l:Loader = new Loader();
   //从 ByteArray 对象中所存储的二进制数据中加载。
   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();
  }

  }
}
}

Copy after login

PHP:

//后台scoket程序,由于适用php写比较简单,就用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") {
  //读取主程序数据
  $f = fopen('main.swf','r');
  $data = fread($f,filesize('main.swf'));
  fclose($f);
  //转换为字符串
  //echo base64_encode($data);
  $talkback = base64_encode($data).'end';
  }
  //发送
  socket_send($msgsock, $talkback, strlen($talkback),0);
} while (true);
socket_close($msgsock);
} while (true);
socket_close($sock);
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/864935.htmlTechArticlephp communicates with flash as3 socket to transfer files to implement the code. Some time ago, I saw someone mentioned on flashseer: it can be done through socket method to transfer swf files, so that users cannot obtain the swf files... At that time...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template