Chapter 10: Using the XMLSocket Class


If youve worked through this book, youll have seen several different ways to include XML content within a Flash movie. In general, we used one of two approacheswriting ActionScript to work with XML or working visually with the data components and Component Inspector panel. In Chapter 4, we explored the methods , properties, and events of the XML and XMLNode classes. We worked with the data components in Chapters 8 and 9. In all the examples, each time we wanted to include XML information in a movie, we had to request it first from an external source.

When you work with the XML class and data components, Flash uses the request response model. Flash must request XML information and receive a response before you can include the information in your Flash movie. Flash doesnt remain connected to the XML data. Each time the data changes, the movie wont update until Flash makes another request. If your data changes frequently, Flash will have to keep making requests to make sure that it has up-to-date information. As you can imagine, this is a very inefficient way for Flash to work.

An alternative is to work with the XMLSocket class. This class allows you to keep an open connection with a server. The server can push information into Flash in real time without Flash having to initiate the contact first. If your data changes regularly, XMLSocket objects allow your Flash movie to respond automatically to each change. For example, you could build a news display that always shows the latest news from an XML feed.

XMLSockets also allow multiple users to interact within Flash movies. Users send information to a server, and it is broadcast to the other users. You could use XMLSocket objects with a chat application or a multiplayer game. In this chapter, youll build a simple chat application.

Computers all over the Internet communicate using sockets. You use a socket every time you connect to another computer or send an email. A socket server is a piece of software installed on a computer, often written in Java or C++. The software listens on a specific port and responds when it receives new information.

For those technically minded readers, socket servers communicate with Flash in a very specific way. They must send their content over a full-duplex TCP/IP stream socket connection. Each message from Flash must be terminated by a zero byte.

Before you can get started with the XMLSocket class, you have to choose and install a socket server. You can write your own socket server using Java, C++, PHP, or ASP.NET. You can also buy a socket server from a vendor. Youll see a list of common socket servers in Table 10-1.

Whichever option you choose, you need to know that installing and working with socket servers can be quite frustrating. Depending on which socket server you choose, you may have to install the Java Runtime Environment (JRE), set up database tables, and configure the socket server settings.

Foundation XML for Flash
Foundation XML for Flash
ISBN: 1590595432
EAN: 2147483647
Year: 2003
Pages: 93
Authors: Sas Jacobs

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: