FlashNOW Documentation V1.3blankarea text

Version 1.3 documentaion is only available in the PDFD format, you can download the PDF .


FlashNOW Documentation V1.2

What is FlashNow ?

FlashNow lets Flash developers easily create live real-time interactions over IP networks. Applications include games, text and avatar chats, whiteboards, virtual classrooms, animated story environments, shared simulations, collaborative applications and other multiuser Flash-based facilities

The FlashNow server works with the XML socket feature, opening a channel for messaging between different users. XML provides a structure for the message,but the server will support any alphanumeric string data. The registered version of the FlashNow package runs under NT or Linux, and supports up to 64 simultaneous users. For testing and development purposes an unregistered version of FlashNow supports up to five users.

 

Installation

Windows Version

To Install FlashNow, download the FlashNowInstall.exe from the FlashNow website (www.nowcentral.com). Save the file to your hard drive. Next, run the FlashNowInstall.Exe file and follow the installation instructions. The instructions will ask you to choose a directory in which to save the files.

Run NSBasic.exe or chose from the start menu "Start | Programs | NowServer | Start NowServer" to activate the server. NowServer handles the XML socket messaging for all FlashNow applications. This must be active before running any of the example files.

In order to shut down the server delete the (application_name).pid file or run NSBasic.exe -s or chose from the start menu "Start | Programs | NowServer | Shutdown NowServer"

Linux Version

Installing the NowServer can be done in 5 simple steps

1. Unpack your distribution file. (recommended location /usr/local/bin/NowServer)
You will have downloaded a file named flashNow.v1.2.tgz. Untar this file with a command like: tar xzvf flashNow.v1.2.tgz - this will create a NowServer directory; cd into this new directory. Change the permission on the NSBasic-1.2 file to make it executable with a command like: chmod 755 NSBasic-1.2.

2. Starting the NOWServer.
Start server with the following command: ./NSBasic-1.2. The following text should appear "Starting NowServer on port 5525." To change the port for the NowServer, please read the instructions in the documentation.

3. SysV startup script is also included NowServerStartup to use this script copy it to your /etc/rc.c/init.d directory and add it to your startup runlevels.

(use the "ntsysv" configuration tool to easily add the script to your runlevels.)
Note: if you have extracted the NSBasic-1.2 binary to a location other than the suggested "/usr/local/bin/NowServer" you will need to edit this startup script.

4. Edit the included NowServer.xml configuration file to customize the settings for your system.

5. To use the examples BeerClient-1.2.pl and SimpleNowArchiver-1.2.pl.
You need to install the Perl modules IO::Socket, Getopt::Mixed, and constant

 

Working with FlashNow

The Basics
FlashNow
makes it possible to create Flash movies that communicate instantly with other Flash movies over the Internet. This means that you can use Flash to develop all kinds of synchronized multimedia and multiuser applications, from chats to games to virtual classrooms and collaborative environments.

To enable live interaction with FlashNow, your Flash movie must do three things:

  • It must set up the XML socket and connect to the computer running the FlashNow server. This could be the localhost, or it could be a remote computer.
  • The movie must be assigned a channel. This is a unique identifier (it can be a number or alphanumeric string) that allows you to establish multiple FlashNOW sessions on the same port.
  • Finally, the movie must pass a name to the server to identify this instance of the client.1

Simple Dynamic Flash Example (Echo)
Echo.fla contains a simple Flash movie, with the bare minimum of functionality: it makes a connection with the NowServer2, takes input, and then sends it back to the user.

The first symbol of interest is the LiveCode movie clip. This movie clip contains the standard initialization routines for any NowEnabled3 movie. It creates a new XML socket and opens a connection to the server. There is also an init() function, although there is nothing to initialize in this movie.

Next, there is newConnection(), which is called as soon as the program connects to the server. It simply displays an appropriate message in outputText.

Finally the function newXML() is called by the server whenever any XML event is sent by any program on the same channel. It parses the XML data character by character, and sends it on to parseMessage().

There are two textfields, inputText and outputText. There is also a "send text" button, placed just offstage. The button is there to trigger events when receiving keystrokes, in this case the <Enter> key.

The first frame of the main movie is the parseMessage() function. This function traverses the XML tree looking for a message node. The top-level XML node in this case is the <LiveEvents> node so it moves on to the first child node. This first child node is a <message> node, so it looks to see if there is a command parameter with the value of "CHAT". If there is, it places the value of the data parameter into outputText.

The "send text" button code should be fairly straightforward to understand. Whenever the <enter> key is pressed, it checks to make sure that there really is something in the inputText to send. If there is, it constructs an XML message containing the data, and sends it to the FlashNow server. Then it erases the inputText field.

This program contains all of the basic functionality of the FlashNow server.

Building a Basic Chat Room
From here it is fairly simple to expand echo.fla into an actual chat room.

The most important new feature to add is the user list. basicChat.fla has a list of users, and automatically generates a random username.

The first thing that the movie does, after loading and connecting with the server, is to call init(). Every time a new user joins, a current user changes names or a current user disconnects, a USERLIST message is generated and sent to every movie on the channel. The XML sent by the server looks like this.

<USERLIST>
<USER name='Guest87'/>
<USER name='Guest66'/>
<USER name='Guest95'/>
</USERLIST>

The parseMessage() function has some added checks to see if the message received was a USERLIST or USER.

  • If the nodeName= USERLIST, it clears the user list in expectation of a new set of USER name values.
  • If the nodeName=USER, it adds the value of the name parameter to the userList text variable.

For this example, users can change or input their name on the same page, using the "submit" button. The code on the submit button sets the local username variable to the text entered, and sends a <SERVER NAME4=''nameOfServer"/> message to the server, just as it did after first connecting to the server.

Note: Instead of requiring the user to change their name on the same page, as in this example, you could construct a login page, with a little code (using PERL or PHP, for example) that passes the user name to Flash. You could also validate a registered user in the login process.

In the example, you will also see a button called USERLIST. When clicked, this button sends another special SERVER XML command <SERVER CHANNELLIST=''theChannelOfThisMovie"/>.

Since a new user list is automatically sent each time a change occurs in the status of the connected users, this command may seem extraneous, and in fact when you click the button you will probably not see a change in the user list. But notice that the name of the channel that the client joined is sent as the CHANNELIST parameter. By using this function, you can request a user list for a foreign channel. You can also turn off the server's automatic user list feature (see the configuration section) and handle the user list using your own custom code, or you can eliminate the user list altogether. (Note that this method of getting a server-generated user list will work even when automatic user list is turned off.)

basicChat.fla adds one more script, attached to a symbol (a movie clip this time), that checks to see if the entered text is still visible. When the user enters more lines of text than will fit in the outputText window, scrollCheck sets the .scroll property to .maxscroll, which keeps the text in the window.

Pushing Events
It is important to note that although most of the XML commands in the first two examples have been of the "CHAT" variety, there is no limit to the type of command that can be sent. This assumes that there is code somewhere to tell the client program what to do with each type of command.

complexChat.fla contains a similar chat program, except that it scans each input line for the characters *LOL*, the old IRC abbreviation for "Laugh out Loud". If it sees these characters, it sends the "CHAT" command as normal, but it also sends a "PLAY" command. This message uses the data parameter to pass a string that is the name of a sound object declared in init().

The "SEND TEXT" button that scans for the <enter> key has a bit more complex code this time. It starts out as before, checking that there really is data in the inputText field.

Then it starts an XML message, but does not include the </LiveEvents> tag to close it. It converts the input string to upper case, and then searches it for "*LOL*". If the text is found (note that the indexOf() method returns -1 if it is not found), then a second message tag is added. This is what tells Flash to play the "laugh" sound.

This example also uses the escape() function to deal with characters such as the double-quote. The parseMessage() function is modified to unescape() the data that it receives. Try typing "I can't live without FlashNOW" in basicChat.fla, and then in complexChat.fla.

In this release of FlashNow, we have added a Private Message feature. First note that when we build the user list the userList dynamic text field now has the HTML checkbox marked. In parseMessage() we build a HTML document, with each name a href link. The strange format of the URL in the href tag <A HREF="asfunction:_root.PrivateMessage,Guest99"> makes use of an undocumented Flash feature, asfunction:. The "asfunction:" feature works much like the "javascript:" URL syntax, but rather than calling a javascript function included in the movie's parent HTML page, the "asfunction:" URL calls an ActionScript defined inside the Flash movie itself. In this case we call the PrivateMessage() function and pass it the name of the user we just clicked on.

The PrivateMessage() function is also included on frame 1 of our Flash movie. Examining this function, we see that it looks almost exactly like the ActionScript used on the "send text" button. The important difference is the addition of a targetuser parameter in the message being sent:

  • When using the suggested <MESSAGE /> syntax the server will look for a targetuser in the sent XML.
  • If none is included, then the message is sent to all clients on the channel.
  • If there is a targetuser, the message is sent only to those clients whose names match the value sent for targetuser.

There are many other useful commands that could be implemented in addition to those just described ("SERVER NAME", "SERVER CHANNEL", "SERVER CHANNELLIST", "CHAT" and "PLAY"). Anything that Flash 5 can do, can be communicated from one Flash application to another through an XML message.

This example also includes basic scrollbars to view previous lines of text. There are four new variables for each scrollbar: percent, start, location, and max.

  • Percent keeps track of the percentage of the scrollbar that the handle has covered.
  • Start is the pixel coordinate of the top of the scrollbar (where the handle starts).
  • Max is the bottom of the bar (where the handle ends).
  • Location is the current location of the text being scrolled.

Thirty times a second - onClipEvent(enterFrame) - location is computed, based on the text's .maxscroll, and .scroll is set.

 

XML Syntax

XML is an approach to structuring data. You can use any valid XML message with FlashNow (in fact the server supports any alphanumeric string.)

There is a recommended syntax, however, if you want to make use of certain advanced NowServer functionality, such as Private Messaging, the Message Timestamp, Archiving Server plug-in, or http tunneling.

The recommended syntax is defined below:

FORMAT:

<LiveEvents version="" encoding="" >
<message timestamp="" channel="" user="" command=""
type="" separator="" data="" recipient="" target="" />
</LiveEvents>

PARAMETERS:

version:float, optional
encoding:string, optional
usage: indicate usage of non-UTF5 message encoding
timestamp:string, Do not Send this event.
(if you use this recommended format the NowServer will add this parameter to your message node. This can be useful in complex interactions such as simulations and interactive gaming)
channel:int, optional
usage: required for use with "firewall tunneling" version of the NowServer
user:string
usage: tracks or displays ID of user from which a message is received
type:string
usage: indicates type of "data" in a complex application where many message types are to be sent and need to be handled differently by your movie. possible values "string", "num", "list" (e.g. if num call parsInt on data, if list call split on data.
separator:char, optional
usage: only necessary if type is list (e.g. "," for a csv list)
data: string
usage: main body of the message (e.g. chat text, name of clip to play, list of x,y location coordinates)
Targetuser:string, optional
usage: private messaging (only a client whose name matches this string will receive the message)

 

 

Other Resources

Macromedia Flash 5 documentation:

ActionScript Reference Guide
First Edition, July 2000

  • Chapter 5: Integrating Flash with Web Applications (p125-136)
  • Chapter 7: Action Script Dictionary, XML Object (p399-426)
 

Configuration

Upon starting, NowServer reads the NowServer.xml. If the file does not exist a default version will be created when you run NowServer. Edit this file with a basic text editor or XML editor to customize your server settings

<NowServer daemon="0" piddir=".">
  <registration username="" serialnumber="" />
  <extensions enableuserlist="1"/>
  <connection transport="any" port="5525" superchannel="1" />
  <http rootdir="./NowWebRoot" poll="0" >
    <mime-type content-type="text/html" extension="html" />
    <mime-type content-type="application/octet-stream" extension="class" />
    <mime-type content-type="application/java-archive" extension="jar" />
    <mime-type content-type="application/x-shockwave-Flash" extension="swf" />
  </http>
</NowServer>

 

registrationWhen you register you will receive a username and serialnumber. Enter your values here to enable the full functions of the NowServer. (See below.)
connection port This is the port on which your server will listen for a new connection, and must match the port you set in the Flash file. Note that Flash XMLSocket only supports ports above 1024. (The NowServer supports using any valid port, but your Flash movie will not be able to connect if the port number is below 1024.) The default port on which NowServer runs is 5525.
connection superchannelThe identifier used for special superchannel clients. Normal Flash XML clients will not work when connecting to the superchannel. Basically, a client on the superchannel will receive all the messages sent to any of the open channels on the NowServer, and can also send a message to any of the open channels as well. It is the extra information that makes this channel not work with normal XML clients. (The BeerClient and SimpleNowArchiver clients can use the superchannel.) The superchannel is useful for building "server plugins" such as archiving or administration systems, or for building relay chains of multiple servers. This is a powerful feature. Look for more examples and documentation as we will update nowcentral.com.
connection transportValid values are "any", "TCP", or "HTTP". HTTP transport is used for firewall support. Examples and documentation on using this function will be added to the nowcentral.com website shortly. If you are using the server for Flash XML Socket clients you will not have to change any of the "<http>" Node or the transport parameter; this is only used for http firewall tunneling.
extensions enableuserlistDefault is 1 (on), or use 0 (off). When this extension is on the server will automatically send a user list when any client joins a channel, leaves a channel, or changes its name. This feature is very useful for a chat or other community application, but in some cases you may wish to implement your own user list. This function could be incompatible or unnecessary with some applications.
NowServer daemonOnly used by the UNIX version of NowServer. Use 1 for daemon mode and 0 for console mode. (The Windows executable automatically runs in daemon mode. A second "console version" is included in the Windows install which would be similar to the non daemon mode)
NowServer piddirUNIX administrators may also want to set the piddir to match other servers on their system, and to make use of startup scripts. (See the readme file and startup scripts included with the UNIX server)

You can also set the parameters with command line switches without editing the configuration file. These changes are not saved and affect only the server started with these flags.

Example usage:

LiveServer [options]

POSIX options:GNU long options: \n
-h--helpthis screen
-c--configconfig file
-p num--port=numport number
-r dir--httprootdir=dirhttp root directory
-s--shutdownshutdown server
 

Registration

When you register FlashNow you will receive a username and registration number via E-mail. Edit the NowServer.xml with a text editor or XML editor. Add the registration node to the NowServer node.

<registration username="john doe" serialnumber="984jc84jc8" />

When you restart NowServer, you will have full access to its features.

 

Tips and Tricks

Flash Security Model

It is important to note that when you are ready to post your NowEnabled applications, the NowServer will need to be running on the same domain as your web server or a sub domain of the web server. In the simplest case you will simply run the NowServer on the same computer as your web server. However, if you have multiple web servers you should look at the Flash documentation regarding the Flash security model.

The only exception to this is that a .swf file loaded from a local drive can connect to any sever, so you can connect to a remote NowServer easily when authoring your Flash application.

Channels

You can have up to 32,000 different channels. Each channel is a completely separate message channel. All users on a channel will receive messages from all other users on the same channel. You can use almost any string as a channel identifier.

If you look in the NowServer.xml configuration file you will note a parameter called superchannel; by default this is set to 1. This superchannel is used by server plugins, and to synchronize multiple servers into a server farm. Therefore, any normal Flash client which attempts to connect on this channel will not get messages in the form expected, and messages sent from it will not be properly routed. Using this you can build synchronized applications that support tens of thousands of simultaneous users, or system and games that require server plugins like Agents, bots, or game rules. Check back at nowcentral.com for more documentation and example code for building server plugins and chat bots.

Latency

Latency is the delay between when you send a message and when everyone else receives it. Latency with the NowServer is extremely low. Normally it is below 300ms, whereas a HTTP chat will often have a latency of over a second. However, network conditions (e.g. the Internet "weather") will affect your latency.

Applications like Chat and turns-based games should not have any problems with the latency issue in the worst conditions.

But interactive games where all users are playing at the same time will be sensitive to the message latency. There are many ways of dealing with this latency. One is to design your game where the speed of play is slow enough to absorb the differences in time.
When doing this you can test latency by counting how long it takes for a client to get its own messages back, and warn users when they fall below an acceptable latency. Also remember that latency on your local network will often be less than that experienced by far flung internet users.

Another option is to use the Timestamp parameter, which the NowServer can add to your message, to mediate which action takes precedence.

SimpleNowArchiver

The SimpleNowArchiver is a sample client written in PERL, which connects to the NowServer and prints all messages received to the console. This tool can be very useful while developing and debugging your FlashNow applications. You may pass the SimpleNowArchiver several command line parameters, listed below with the default values

port -p 5525
channel -c 1
name -n Archiver
host -h localhost

Example usage:

SimpleNowArchiver.exe -h yoursever.com -p 1024

  • The SimpleNowArchiver supports the "superchannel" (channel 1) mentioned earlier in configuration, which means that if you use the default channel value "1" the SimpleNowArchiver will print messages sent to all the channels in use on you NowServer.
  • To exit the SimpleNowArchiver, type Ctrl-C in the console


An .exe and the PERL Source for SimpleNowArchiver are included with the development tools. If you have PERL installed you can use and modify the SimpleNowArchiver.pl file to add server side functionality to your system

Beer Client

The BeerClient is another sample client written in PERL, which can be used for debugging. The BeerClient sends messages to the NowServer automatically on a timed basis. It has the same command switches as SimpleNowArchiver, as well as a few additional command line parameters, listed below with the default values:

port -p 5525
channel -c 3
name -n BeerClient
host -h localhost
command -k CHAT
message -m $i on the wall
delay -d 3

Example usage:

BeerClient.exe -h yourserver.com -p 1024 -k DRINK -m $i bottles to go

  • Command and message allow you to customize the XML message sent to a small degree. If you use "$i" in your message string, it will be replaced with a countdown value starting at 99 and decreasing by one for each message until its value is 1.
  • Delay is the number of seconds BeerClient waits between sending XML messages.
  • The BeerClient will send 99 messages and then automatically exit. (Hence the name. "99 bottles of beer on a wall, 99 bottles of beer…")
  • To exit the BeerClient manually type Ctrl-C in the console.


An .exe and the PERL Source for BeerClient are included with the development tools. If you have PERL installed you can use and modify the BeerClient.pl file to add server side functionality to your system.

Endnotes:
1. FlashNow does not require this name to be unique for each client, but functions like HTTP tunneling do require a unique name in order to work correctly. One will typically use the "username" for this identifier.

2. NowServer is the synchronous server that installs with FlashNow.

3. We use NowEnabled to describe an application that has been programmed to use NowServer for multiuser interaction, online synchronization, etc.

4.SERVER NAME is called whenever a user name is set or changed.

5.UTF (Unicode Transformation Format)

FlashNow, NowServer, and NowEnabled are registered trademarks of Learning Worlds, Inc.

FlashNow © 2001, Learning Worlds, Inc. All rights reserved