Sunday, July 25, 2010

Flash Bridged Web Sockets in Node

Many people are talking about how to use websockets and where they are supported. Luckily we can use a Flash substitute in cased that they are not natively in Javascript. In this post I will create a small example of using this fallback technique. Our example will be a simple publish/submission chat.

For the example we are going to create we will need a few things:


Note:
  • Flash websockets will not be active until the SWF is loaded, either wait for an onload or test other ways to see if the WebSocket interface is ready.
  • IE 64-bit does not support Flash as of the time of this post.
Websocket Client:

web-socket-js has a sample.html file which will serve as our example of a simple publication/subscription service client. It requires WebSocketMain.swf , swfobject.js , web_socket.js , and FABridge.js . All the browser will have to do to get to this is direct to this page from HTTP:// (Flash Sockets will not work on FILE://)

The only modifications to this file that we need to do are where the WebSocket(url) is going.

  • If you move WebSocketMain.swf be sure to set WEB_SOCKET_SWF_LOCATION
  • You can remove WEB_SOCKET_DEBUG if you do not want messages in your console

Websocket Server:
Our server needs to do 3 things:
  1. Serve the files we want to make up our client
  2. Accept websocket connections
  3. Serve a policy file using TCP (Not HTTP://!)
To see all of these in action download:

0 comments:

Post a Comment