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 VERSION:int = 1;
public var my_txt:TextField;
public function SocketExample(){
Security.loadPolicyFile("xmlsocket://www.0chan.ru:1843");
sock = new Socket();
sock.addEventListener(Event.CONNECT, connected);
sock.addEventListener(Event.CLOSE, disconnected);
sock.addEventListener(IOErrorEvent.IO_ERROR, ioerror);
sock.addEventListener(ProgressEvent.SOCKET_DATA, read);
var _local1:uint = setInterval(temp, 5000);
connect();
}
private function connect(){
sock.connect("www.0chan.ru", 1984);
}
private function ioerror(){
my_txt.htmlText = (my_txt.htmlText + "Какаято хуита!");
}
private function temp():void{
chars = "ABCDEFGHGKOPQRSTUVWXYZ123078934\\'&&&7777723234";
txt = "";
tmp_ch = Math.round((100 * Math.random()));
i = 0;
while (i < tmp_ch) {
tmp = Math.round((chars.length * Math.random()));
txt = (txt + chars.charAt(tmp));
i++;
};
trace(txt);
sendString(txt);
}
public function read(_arg1:ProgressEvent){
var _local2:int;
var _local3:int;
var _local4:int;
_local2 = 0;
while (_arg1.bytesLoaded > _local2) {
_local3 = sock.readUnsignedShort();
_local4 = sock.readByte();
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;
default:
break;
};
_local2 = (_local2 + ((_local3 + 2) + 1));
_local3 = 0;
};
}
public function sendString(_arg1:String){
_arg1 = _arg1.substr(0, 0xFF);
sock.writeUTFBytes(_arg1);
sock.flush();
}
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 + "Отключились");
}
}
}//package