Example using Flash?

May 29, 2012 at 2:28 AM

Does anyone have a working example of a Flash bridge and SuperWebSocket?   I've been trying for hours to get it working with web-socket.js, but can't get it to work.      


May 29, 2012 at 8:15 AM

Did you take care of things about socket access policy?

May 29, 2012 at 6:27 PM

Hey Kerry, thanks for the quick reply.   Dealing with the policy is just the thing I'm having problems with.   I keep getting the following error...

[WebSocket] cannot connect to Web Socket server at ws://localhost:8765 (SecurityError: Error #2048) make sure the server is running and Flash socket policy file is correctly placed

I've added a crossdomain.xml file to the root of the site with the following...

<?xml version="1.0" ?>
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="*"/>
    <allow-http-request-headers-from domain="*" headers="*"/>

This of course does not work.   Here are some other things I've tried.

  • Loading the file manually using WebSocket.loadFlashPolicyFile("http://localhost:2111/crossdomain.xml").   This is translated to action scrips loadFlashPolicyFile method behind the scene.   The crossdomain.xml is sent over the wire, but the same error occurs.
  • Serving the file from port 843.   So any request to "http://localhost:843" returns the crossdomain.xml file.    Same error.   I've even tried loading it with loadFlashPolicy also, but same error.
  • Setting DisableSockets=0 in mms.cfg... Same error.
  • Adding the flash server config to the SuperSocket config as specified here http://supersocket.codeplex.com/wikipage?title=How%20to%20enable%20built-in%20Flash%2FSilverlight%20policy%20server.   Same error.

No wander most developers hate flash.   Any other suggestions?    If anyone has a working sample, that would perfect.

May 30, 2012 at 1:29 AM

Could you make sure your crossdomain.xml can be accessed by the address http://localhost/crossdomain.xml?

Jun 2, 2012 at 12:47 AM

Yes I can view the XML in the browser by navigating to http://localhost:2111/crossdomain.xml.   If I use the loadFlashPolicyFile(..) method to load the file, I see that a GET request is made, and the crossdomain.xml is returned.    The same error is thrown though.


If I do NOT use the loadFlashPolicyFile method... then the following is logged to the console...

[WebSocket] policy file: xmlsocket://localhost:843

No request is ever made though.   The same error is shown after about 6 seconds...   

[WebSocket] cannot connect to Web Socket server at ws://localhost:8765 (SecurityError: Error #2048) make sure the server is running and Flash socket policy file is correctly placed

Jun 2, 2012 at 3:53 AM
Edited Jun 2, 2012 at 3:54 AM

Okay for wasting a number of hours on it, I've figured out a solution.   It seems that it is required that a policy file is returned from port 843, otherwise flash will throw the error.    The following code below fixed it for me.    I tried to use the SuperSocket server, but it never worked for me.   I basically run this code within ASP.NET during app start.


        private TcpListener _tcpListener;

        private void StartFlashPolicyServer()
            _tcpListener = new TcpListener(IPAddress.Any, 843);
            _tcpListener.BeginAcceptSocket(ReturnFlashPolicy, _tcpListener);

        private void ReturnFlashPolicy(IAsyncResult result)
            TcpListener listener = (TcpListener)result.AsyncState;
            Socket client = listener.EndAcceptSocket(result);
            NetworkStream stream = new NetworkStream(client);
            StreamReader reader = new StreamReader(stream);
            StreamWriter writer = new StreamWriter(stream);

            //Create policy XML
            var port = GetSetting<int>("PubSubPort");
            var response = "<cross-domain-policy>" +
                                "<site-control permitted-cross-domain-policies=\"all\" />" +
                                "<allow-access-from domain=\"*\" to-ports=\"" + port + "\" />" +
            //Return policy

            //Close all
            //Restart listener
            _tcpListener.BeginAcceptSocket(new AsyncCallback(ReturnFlashPolicy), _tcpListener);
Jun 2, 2012 at 6:45 AM

Same with Silverlight, Flash should also have two policy file access protocol, Http, Socket.

If you want to use socket policy access protocol, you can use SuperSocket bult-in policy socket server:



Jun 2, 2012 at 7:04 PM

Okay great thanks for the assistance Kerry.   And thanks for the great library!!

Jun 23, 2012 at 7:25 PM
Edited Jun 24, 2012 at 10:12 AM

If we use

socket.Setup(new RootConfig(), new ServerConfig {...

How can we specify policy for flash compatibility?

EDIT: I found this: http://superwebsocket.codeplex.com/discussions/273098

EDIT2: Same problem
[WebSocket] cannot connect to Web Socket server at ws:// (SecurityError: Error #2048)
make sure the server is running and Flash socket policy file is correctly placed

My configuration:
socket = new WebSocketServidor();
ServerConfig sc = new ServerConfig{ 
   Port = 8181,
   Ip = "any",
   Name = "servidor",
   MaxConnectionNumber = 10000,
   Mode = SocketMode.Async,
   ReceiveBufferSize = 2048,
   SendBufferSize = 2048
sc.Options = new System.Collections.Specialized.NameValueCollection(); 
sc.Options.Add("policyFile", "Policy\\flash.xml");
socket.Setup(new RootConfig(), sc, SocketServerFactory.Instance);

And Flash.xml: 

<?xml version="1.0" encoding="utf-8" ?> 
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="*"/>
    <allow-http-request-headers-from domain="*" headers="*"/>

Jun 26, 2012 at 2:39 AM


var policyServer = new SilverlightPolicyServer();

It is NOT socket = new WebSocketServidor();


You'd better creat two appServer instances, one for your application, one for the policy server.

Jun 26, 2012 at 2:48 PM

Very thanks kerryijang! Runing on IE9.

For other people, I used this xml:

<?xml version="1.0" encoding="utf-8" ?> 
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="*"/>
    <allow-http-request-headers-from domain="*" headers="*"/>


Jun 1, 2013 at 11:35 AM
Thanks for the great work.

I want to use the WebSockets to connect to server if the browser is having Websocket feature else use Flash bridge to connect to the server.I hosted the policy server with the above policy file in a console application (In the same console application I also hosted my SeperWebSocket server).

I know how to connect to WebSocket server from browser,but I am unable to connect using flash bridge if the browser does't support WebSocket.Could you please provide me the client script (which I need to write in browser) to connect using flash.

Thanks in advance.
Jun 2, 2013 at 4:34 PM
Please refer to this project:
Jun 4, 2013 at 5:27 AM
Thanks a lot kerryjiang. You solved my problem. Now I am able to work with IE9 and below with help of Flash bridge.