websocket的全完全解决方案(兼容ie9)

1、客户端的页面用下面这个地址,运行sample

https://github.com/gimite/web-socket-js

2、服务器端用下面这个即可
https://github.com/statianzo/Fleck

3、按照上面的步骤还不能支持ie9
要执行下面这个服务,拷贝下面的代码,生成一个控制台程序,然后在服务器端执行着

在Adobe Flash Player升级到9.0.124后,由于安全策略的更改,使得在socket或xmlsocket的应用里,原先如用http方式加载安全策略的手段不能继续使用了,类似此类应用必须使用xmlsocket://方式来提供安全策略。flashplayer的安全策略检测过程如下:

1,首先检测目标服务器的843端口是否提供安全策略

2,如果1没有检测到策略,则检测actionscript是否使用了

Security.loadPolicyFile(xmlsocket://)

手段提供安全策略,如果还没检测到,则使用第3步检测

3,检测目标服务器目标端口是否提供安全策略

C#代码如下,编译环境VS2008 + .NET framework 3.5

using System;  

using System.Text;  

using System.Net;  
using System.Net.Sockets;  
using System.Threading;  
using System.Collections;  
   
namespace serverSocket  
{  
    class Program  
    {  
        private Thread Beginthread, receivethread;  
        private Socket serverSocket, ClientSocket;  
   
        static void Main(string[] args)  
        {  
            Program program = new Program();  
   
            IPEndPoint remotePoint = new IPEndPoint(IPAddress.Any, 843);  
   
            program.serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);  
   
            program.serverSocket.Bind(remotePoint);  
            program.serverSocket.Listen(10);  
   
            Console.WriteLine("Listening...");  
            program.Beginthread = new Thread(new ThreadStart(program.BeginListen));  
            program.Beginthread.Start();  
        }  
   
        private void BeginListen()  
        {  
            while (true)  
            {  
                ClientSocket = serverSocket.Accept();  
                receivethread = new Thread(new ThreadStart(receive));  
                receivethread.Start();  
            }  
        }  
   
        private void receive()  
        {  
            IPEndPoint clienTep = (IPEndPoint)ClientSocket.RemoteEndPoint;  
   
            int bytes = 0;  
   
            while (true)  
            {  
                Byte[] buffer = new Byte[24];  
                bytes = ClientSocket.Receive(buffer);  
   
                if (bytes > 0)  
                {  
                    string clientCommand = Encoding.UTF8.GetString(buffer, 0, bytes);  
   
                    String policy = "<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"2999\" /></cross-domain-policy>\0";  
   
                    buffer = System.Text.Encoding.UTF8.GetBytes(policy.ToCharArray());  
   
                    ClientSocket.Send(buffer, buffer.Length, 0);  
                }  
                else  
                {  
                    break;  
                }  
            }  
   
            ClientSocket.Close();  
            receivethread.Abort();  
        }  
    }  
} 

 

posted @ 2017-05-19 13:28  严于律己,宽以待人  阅读(1692)  评论(1编辑  收藏  举报