Home php教程 PHP开发 PHP and flash as3 socket communication and file transfer implementation code

PHP and flash as3 socket communication and file transfer implementation code

Dec 22, 2016 am 09:53 AM
socket communication

Some time ago, I saw someone mention on flashseer: SWF files can be transmitted through socket, so that users cannot obtain the SWF files... At that time, AS3 decompilation had not been released, so the protection of the program was not concerned. With the development of decompilation programs For the common people, friends who don’t want others to see the source code are more anxious...

The idea of ​​​​transmitting swf files through sockets to avoid leaking source codes (only applicable to as3): Let the loader of the main program (front-end swf) connect to the server through sockets The background program then requests 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 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 &#39;socket_create() failed: reason: &#39; . socket_strerror($sock) . &#39;\n&#39;;
}
if (($ret = socket_bind($sock, $address, $port)) < 0) {
echo &#39;socket_bind() failed: reason: &#39; . socket_strerror($ret) . &#39;\n&#39;;
}
if (($ret = socket_listen($sock, 5)) < 0) {
echo &#39;socket_listen() failed: reason: &#39; . socket_strerror($ret) . &#39;\n&#39;;
}
echo &#39;connect…………….&#39;;
do {
if (($msgsock = socket_accept($sock)) < 0) {
  echo &#39;socket_accept() failed: reason: &#39; . socket_strerror($msgsock) . &#39;\n&#39;;
  break;
}
do {
  socket_recv($msgsock, $buf, 2048, 0);
  if ($buf == "") {
  socket_close($msgsock);
  echo "some one quit";
  break;
  } else if ($buf == "bin") {
  //读取主程序数据
  $f = fopen(&#39;main.swf&#39;,&#39;r&#39;);
  $data = fread($f,filesize(&#39;main.swf&#39;));
  fclose($f);
  //转换为字符串
  //echo base64_encode($data);
  $talkback = base64_encode($data).&#39;end&#39;;
  }
  //发送
  socket_send($msgsock, $talkback, strlen($talkback),0);
} while (true);
socket_close($msgsock);
} while (true);
socket_close($sock);
Copy after login

For more articles related to PHP and flash as3 socket communication and file transfer implementation code, please pay attention to the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)