socketserver AS3 client

Download the socketserver AS3 sample client here

(I'm assuming that you have already downloaded and successfully run socketserver before you try to set up a flash client.)

So once you have your server running, possibly even talking to something on a serial port, how about getting out of the text-based world of Terminal and into something a little prettier? Let's go with Flash; it's a pretty well established development environment, and nowadays with actionscript 3 you can extend it to do just about anything you want. All we're going to do is run the server, start this client, and send some messages over the server to flash. When flash gets the messages, it will print the message on the screen. Pretty simple, huh?

If you decompress and open the downloaded directory (SocketServerAS3Client) you will see 3 things: an .fla file (that you can mess around with), a published .swf file (it should be noted that this swf was created with network-without-filesystem privileges... maybe some day I'll write up a simple description of what flash will and won't let you do when messing with servers), and a folder named 'com'. When you mess around with the .fla, it's important that you have the 'com' folder (and all of its contents) in the same directory as the .fla; 'com' has the definition of a CustomSocket class in it, and that's what we're using to talk to the server.

So let's get this running! I'm providing instructions for OS X and will add instructions for Windows to this page when I get around to writing the Windows version of socketserver, but the actual instructions will be about the same:

  1. In Applications>Utilities, start Terminal.
  2. Navigate to the decompressed directory for socketserver.
  3. Start socketserver with the following command: [pathToSocketServer]:~[yourName]$ ./ -v -c -l 6780
  4. If chat mode cannot be enabled (it should say this when it starts, but unless you've updated your version of PHP all versions of mac OS X prior to 10.5 won't enable chat) you'll need a way of typing messages, so open a new Terminal window and start telnet: [path]:~[yourName]$ telnet 6780
  5. In finder, browse to the decompressed folder that contains SocketServerAS3Client.swf and double-click it.
  6. Type something, either in socketserver or telnet.
  7. Enjoy! What you typed should show up in the flash player.

There are a lot of places for the above instructions to go bad. Let's start with the most obvious one: you don't have the standalone flash player. That's easy if you have the flash plugin for your web browser... just drag the swf into an opened browser window and the browser's flash plugin will play it fine. There are also a lot of ways to mess up the server setup, but I've covered that setup on another page.

If it actually worked for you and you have Flash CS3, you should open the fla and play with it. Here are some things to try:

  • Validate messages from socketserver; check for all caps, all numbers, or some other validation.
  • If you can validate that messages are numbers, it would be a reasonable extension that those numbers could change the position of something on the stage...
  • Practice creating a protocol for messages, then make flash ignore all messages that don't start with 'toFlash' (or whatever your protocol defines messages to flash as).

Here's the download link to the sample files again...
socketserver AS3 sample client