gopush 是金山开源的一个集群推送方案,支持1000k级别的推送,使用golang编写,性能是杠杠的,下面一小编来看看gopush集群推送兼容ie方案吧.
gopush支持tcp 和 websocket 两种协议,在移动端和新浏览器中,可以用tcp与websocket来解决实时推送,但是ie9以下版本IE浏览器是不支持websocket的,一般都是用长轮训来替换websocket,作者发话说短期内不考虑long-polling方式,这里就用flash的方案解决.
首先需要对gopush进行代码调整,以便适应flash 的安全策略,在web/http.go里面加入如下代码:
httpServeMux.HandleFunc("/crossdomain.xml", CrossDomain)
然后在web/handle.go加入如下代码:
- func CrossDomain(w http.ResponseWriter, r *http.Request) {
- hp := `<?xml version="1.0" ?>
- <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
- <cross-domain-policy>
- <site-control permitted-cross-domain-policies="all"/>
- <allow-access-from domain="*.pztai.cn"/>
- <allow-http-request-headers-from domain="*.pztai.cn" headers="*"/> //Vevb.com
- </cross-domain-policy>`
- io.WriteString(w, hp)
- }
然后在gopush下边建立新的文件夹flash,建立main.go,监视843端口,如果有请求,就返回crossdomain.xml内容,断开连接即可,最后用as3写普通的socket代码连接即可,核心代码如下:
- private function sendHead():void{
- //发送协议
- var protocol:String = "*3\r\n$3\r\nsub\r\n$" + key.length+"\r\n"+key+ "\r\n$"+ hearbeattime.toString().length+ "\r\n" + hearbeattime.toString() + "\r\n";
- socket.writeUTFBytes(protocol);
- socket.flush();
- }
- private function socketGetData(data:ProgressEvent):void{
- if(socket.bytesAvailable){
- var msg:String = socket.readUTFBytes(socket.bytesAvailable);
- if(msg.charAt(0) == '+'){
- if(!heatbeatTimer.running){
- socketok = true;
- heatbeatTimer.start();
- }
- if(reconnectTimer.running){
- reconnectTimer.stop();
- }
- }else if(msg.charAt(0) == '$'){
- var msgArr:Array = msg.split("\r\n");
- var msgString:String = msgArr[1];
- ExternalInterface.call("asCallBack"," " + encodeURI(msgString));
- }
- }
- }
新闻热点
疑难解答