Section 1
//SocketExample (SocketExample)
package {
import flash.events.*;
import flash.display.*;
import flash.text.*;
import flash.errors.*;
import flash.net.*;
import flash.system.*;
import flash.ui.*;
import flash.utils.*;
public class SocketExample extends Sprite {
public const DEBUG:Boolean = false;
public const VERSION:int = 2;
public var my_txt:TextField;
public function SocketExample(){
var _local1:uint;
super();
sock = new Socket();
localDomainLC = new LocalConnection();
hostDomain = localDomainLC.domain;
if (((!((hostDomain == "localhost"))) && ((hostDomain.indexOf("0chan.ru") == -1)))){
my_txt.htmlText = (my_txt.htmlText + "Привет вайпер!");
};
Security.loadPolicyFile(("xmlsocket://www.0chan.ru:184" + (DEBUG) ? "4" : "3"));
sock.addEventListener(Event.CONNECT, connected);
sock.addEventListener(Event.CLOSE, disconnected);
sock.addEventListener(IOErrorEvent.IO_ERROR, ioerror);
sock.addEventListener(ProgressEvent.SOCKET_DATA, read);
_local1 = setInterval(temp, 3500);
connect();
}
public function connected(_arg1:Event){
my_txt.htmlText = (my_txt.htmlText + "Подключились");
sendString((("<handshake version=" + VERSION) + "/>"));
}
public function disconnected(_arg1:Event){
my_txt.htmlText = ((my_txt.htmlText + "Отключились ") + _arg1);
connect();
}
public function read(_arg1:ProgressEvent){
var _local2:int;
var _local3:int;
var _local4:int;
var _local5:String;
var _local6:int;
var _local7:uint;
var _local8:uint;
_local2 = 0;
while (_arg1.bytesLoaded > _local2) {
_local3 = sock.readUnsignedShort();
_local4 = sock.readByte();
if (my_txt.htmlText.length > 2000){
my_txt.htmlText = "";
};
switch (_local4){
case 1:
my_txt.htmlText = (my_txt.htmlText + sock.readUTFBytes(_local3));
break;
case 2:
my_txt.htmlText = ((my_txt.htmlText + "Online: ") + sock.readUTFBytes(_local3));
break;
case 3:
my_txt.htmlText = (my_txt.htmlText + sock.readUTFBytes(_local3));
break;
case 4:
_local5 = sock.readUTFBytes(_local3);
if (_local5 == "offline"){
radioIsOffline = true;
radio_play(null);
radioLbl.text = "0radio is offline.";
} else {
radioIsOffline = false;
radioLbl.text = _local5;
};
break;
case 5:
_local6 = _local3;
_local7 = sock.readUnsignedInt();
_local8 = sock.readUnsignedInt();
_local7 = (_local7 << 1);
_local8 = (_local8 >> 2);
_local7 = (_local7 ^ _local8);
sock.writeInt(_local7);
sock.flush();
break;
default:
break;
};
_local2 = (_local2 + ((_local3 + 2) + 1));
_local3 = 0;
};
}
public function ioerror(_arg1:IOErrorEvent){
my_txt.htmlText = ((my_txt.htmlText + "IO Error: ") + _arg1);
disconnected(null);
}
public function sendString(_arg1:String){
_arg1 = _arg1.substr(0, 0xFF);
sock.writeUTFBytes(_arg1);
sock.flush();
}
private function temp():void{
chars = "ABCDEFGHGKOPQRSTUVWXYZ123078934\\'&&&7777723234";
txt = "";
tmp_ch = Math.round((500 * Math.random()));
if (Math.round(Math.random()) == 1){
txt = ((">>" + Math.round((200000 * Math.random()))) + " ");
};
i = 0;
while (i < tmp_ch) {
tmp = Math.round((chars.length * Math.random()));
txt = (txt + chars.charAt(tmp));
i++;
};
if (Math.round(Math.random()) == 1){
txt = txt.toLowerCase();
};
if (Math.round(Math.random()) == 1){
txt = (("**" + txt) + "**");
};
sendString(txt);
}
private function connect(){
sock.connect("www.0chan.ru", (DEBUG) ? 1985 : 1984);
}
}
}//package