让ie6也支持websocket
ie9都不支持websocket,何况ie6,但是websocket能开发那么酷的功能,怎么能让ie拦住我们的脚步?但是怎么办?用flash封装吧具体的flash代码如下:[plain]package {import flash.display.Stage;import flash.display.Sprite;import flash.events.*;import flash.external.ExternalInte易做图ce;import flash.system.Security;import flash.utils.Timer;import flash.net.Socket;import flash.utils.ByteArray;import flash.utils.Endian;public class websocket4ie extends Sprite {public static function main():void{var websocket4ie:websocket4ie = new websocket4ie();}private var debugEnabled:Boolean;private var movieName:String;private var handlers:String;private var server:String;private var port:Number;private var isDebug:Number;private var socket:Socket;private var socketBuffer:ByteArray = new ByteArray();public function websocket4ie() {Security.allowDomain("*");var counter:Number = 0;root.addEventListener(Event.ENTER_FRAME, function ():void { if (++counter > 100) counter = 0; });this.movieName = root.loaderInfo.parameters.movieName;this.handlers = root.loaderInfo.parameters.handlers;this.server = root.loaderInfo.parameters.server;this.port = root.loaderInfo.parameters.port;this.isDebug = root.loaderInfo.parameters.debug;this.debug(this.port+''+this.server);try {this.debugEnabled = root.loaderInfo.parameters.debugEnabled == "true" ? true : false;} catch (ex:Object) {this.debugEnabled = false;}this.connectServer();ExternalInte易做图ce.addCallback("sendData", this.sendData);}public function connectServer():void {socket = new Socket();socket.endian = Endian.BIG_ENDIAN;socket.addEventListener(Event.CONNECT, onConnect);socket.addEventListener(Event.CLOSE, onClose);socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);socket.connect(this.server, this.port);this.socket = socket;}public function onConnect(e:Event):void {//握手var headers:Array = new Array();headers.push("GET /chat HTTP/1.1\r\n");headers.push("Upgrade: websocket\r\n");headers.push("Connection: Upgrade\r\n");headers.push("Host: "+this.server+":"+this.port+"\r\n");headers.push("Origin: null\r\n");headers.push("Sec-WebSocket-Key: 6z4ezNfATjW5/FEMYpqRuw==\r\n");headers.push("Sec-WebSocket-Version: 13\r\n\r\n\r\n");this.socket.writeUTFBytes(headers.join(''));this.socket.flush();}public function onTrueConnect():void {ExternalInte易做图ce.call(this.handlers+".onConnect",this.movieName);}public function onClose(e:Event):void {ExternalInte易做图ce.call(this.handlers+".onClose",this.movieName,'1');补充:Web开发 , 其他 ,
上一个:新兴Web技术杂谈 之 WebSocket
下一个:web数据收集方法分类