Chapter 19
XML Sockets
Goals:

In this chapter we learn to create a full socket system connecting our own remote server and our own Flash clients.

The previous chapter presented a fairly elementary introduction to sockets. We built an XML proxy using fsockopen() a simple function which treats the socket system as an input stream. This allows us to use the familiar methods of file i/o to create simple client sockets in PHP.

In this chapter, we return to the same topics and examine them in far more depth. We now will use PHP to build server sockets, which are far more demanding, and cannot be cast as file operations.. We will also build client sockets in Flash.

We will create a single client / server socket and a live test program that lets us send data on the round trip. After this is accomplished, we will build a multiplex socket system, with more than one client serviced by the host script.

This chapter is of interest to those who need to build low-latency, persistent connections between user and server. A single-user application would typically involve a streaming data feed, such as a market monitor or some sort of remote real-time instrumentation. Or it might require alerts or data pushes (though there are usually easier ways to achieve these).

 

Caution

This subject is interesting, but it is difficult material. The code samples are problematic. They do not require a privileged account., but they do demand the cooperation of your system administrator.

 

The authors and publisher disclaim any responsibility for problems caused by implementing any of this code.

The functions in this chapter can cause real problems for yourself and for other accounts on your server. Permanent damage (eg: file system corruption) is unlikely, but these experiments might result in service interruption - or a bandwidth pinch. Cleanup might require superuser assistance.

 

Code in this chapter must be run on a noncritical server!