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.

Pages: 1 2 3

Bookmark and Share

5 Responses to “Tutorial: Socket server with Flash and Node.js”

  1. EvilPaul says:

    Awesome stuff! Simple and helpful!

  2. James says:

    Awesome post! Thanks for taking the time to write this tutorial.

  3. Mayank says:

    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.

  4. Rhuno says:

    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/

  5. Mayank says:

    Hi,

    Thanks for the tutorials!! they are awesome!!! :) :) :) :)

Leave a Reply

Subscribe to RSS feed