1, the client's page with the following address, run sample
Https://github.com/gimite/web-socket-js
2, the server side with the following can be
Https://github.com/statianzo/Fleck
3, follow the above steps can not support IE9
To perform the following service, copy the following code, generate a console program, and then execute it on the server side.
After the Adobe Flash player upgrade to 9.0.124, due to security policy changes, so that in the socket or Xmlsocket applications, the original HTTP mode to load security policy can not continue to use, similar to such applications must use the Xmlsocket ://way to provide security policy. The Flashplayer security policy detection process is as follows:
1, first detect whether the target server port 843 provides a security policy
2, if 1 does not detect a policy, detects if ActionScript is using the
Security.loadpolicyfile (xmlsocket://)
means to provide a security policy, and if not detected, use the 3rd step detection
3, detects if the target server destination port provides a security policy
C # code below, compilation environment VS2008 +. NET Framework 3.5
usingSystem; usingSystem.Text; usingSystem.Net; usingSystem.Net.Sockets; usingSystem.Threading; usingSystem.Collections; namespaceServerSocket {classProgram {PrivateThread beginthread, Receivethread; PrivateSocket ServerSocket, Clientsocket; Static voidMain (string[] args) { Program Program=NewProgram (); IPEndPoint Remotepoint=NewIPEndPoint (Ipaddress.any,843); Program.serversocket=Newsockets (AddressFamily.InterNetwork, SocketType.Stream, protocoltype.tcp); Program.serverSocket.Bind (Remotepoint); Program.serverSocket.Listen (Ten); Console.WriteLine ("Listening ..."); Program. Beginthread=NewThread (NewThreadStart (program. Beginlisten)); Program. Beginthread.start (); } Private voidBeginlisten () { while(true) {Clientsocket=serversocket.accept (); Receivethread=NewThread (NewThreadStart (receive)); Receivethread. Start (); } } Private voidreceive () {IPEndPoint clientep=(IPEndPoint) clientsocket.remoteendpoint; intbytes =0; while(true) {byte[] buffer=Newbyte[ -]; Bytes=clientsocket.receive (buffer); if(Bytes >0) { stringClientcommand = 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 (); } } }
Fully complete solution for WebSocket (compatible with IE9)