Tutorial: Socket server with Flash and Node.js
Programming with sockets seems to be an intimidating venture for many developers. However, with AS 3 and Node.js, it really isn’t too difficult. In this tutorial you will set up a simple socket server using Node.js and connect to it with a Flash-based client. When the project is complete, you’ll be able to see data being transmitted from Flash to the server and back to Flash again - Booyah!
Getting Started
To get started, you’ll first need to download Node.js. If you’re on a Windows box, you can get the download right here. If not, check out this wiki page for instructions on how to get it on your system. I wrote this tutorial on my Windows 7 machine, so the instructions will target that platform, though you can still follow along and use the appropriate paths on your own machine regardless of which platform you’re using.
Once you have downloaded the package, create a new directory named nodeJS on your C drive. You can extract the contents of the node.js package to this directory. If you want to test out the installation, go into the Node.js bin directory and create a new JavaScript file. Bring up any text editor (notepad is fine) and enter the text below; save the file as helloworld.js.
console.log("Hello, World!");
The actual Node program is a command-line based tool that will execute your javascript files. To run it, bring up the Windows command prompt.
1) hit the Windows key + r to bring up the Run box
2) type cmd in the box and hit enter
With the command window open, we need to navigate to the Node.js bin directory; that is where we saved our helloworld.js file. If you created a nodeJS directory on your C drive as I have done above then type the following in the command window:
cd C:\nodeJS\bin
If you created your directory in a different place, you’ll need to adjust the path accordingly. Now that we’re in the right place, we need to tell the Node program to execute our script. We can do this by issuing the command like so:
node helloworld.js
With any luck, you’ll see the words “Hello, World” printed out in the console window as shown below.
If everything worked, then you’re ready to move on. If not, try repeating the steps and make sure you’ve installed Node.js in the right place.



Awesome stuff! Simple and helpful!
Awesome post! Thanks for taking the time to write this tutorial.
Hi.
thanks for such an awesome post!! was really helpful!
it would be great if you can also post the modified C# file for sending kinect information!
looking forward for a quick reply.
Hi, Mayank.
I did do a couple of tutorial on sending kinect information to Flash via node.js earlier. They may be outdated now as they were done with the original sdk and getting properly set up was somewhat of an involved process. However, if you’re interested you can check out the articles below.
http://rhuno.com/flashblog/2011/07/02/tutorial-kinect-to-flash/
http://rhuno.com/flashblog/2011/09/18/full-body-tracking-with-kinect-and-flash/
Hi,
Thanks for the tutorials!! they are awesome!!!
Thank you for the great instructions. I am liking node and can’t wait to try some more things with it.
Great post. Could you explain how to set up a flashpolicy.xml for this demo? I keep getting the following in my server log: “From Flash = “. The example works when you compile through flash IDE but now when you run the swf independently.
thanks
Hi Marwan,
Depending on where you are running the content from, you may not need a cross doman policy file. If you are running the swf from your machine, you might need to add the location to the list of Flash’s trusted locations. You can do so using the online global security panel here:
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html
If you do need to set up a cross domain file, this article may help you out.
http://active.tutsplus.com/tutorials/tools-tips/quick-tip-a-guide-to-cross-domain-policy-files/
I hope that helps.
thankyou! =*^_^*=