Essential Networking Module User’s Guide : PART II The Networking Package : Chapter 5 Streams : Using Virtual Streams
Using Virtual Streams
The Networking package iostream classes enable you to use any of the virtual streams classes in Rogue Wave’s Essential Tools Module. The virtual streams classes handle the mechanics of reading and writing data into the various streams and formats, but your application must create helper functions for every class that will be transmitted over a stream. These helper functions read and write the instance variables of a class. For more information, see the SourcePro API Reference Guide.
Constructing a Portable ASCII Virtual Stream for Output
Example 7 shows how to construct a portable ASCII virtual stream for output using an RWPortalStreambuf.
Example 7 – Constructing a portable ASCII virtual stream for output
RWPortalStreambuf buf(portal);
RWpostream ostrm(&buf);
The streambuf object buf must remain in scope as long as the output stream is being used because the output stream keeps a pointer to the streambuf. If buf goes out of scope, the pointer in the output stream becomes invalid, and when the stream attempts to write bytes, the application will fail.
Constructing a Binary Virtual Stream for Input from a Portal
Example 8 is similar to Example 7, except that it sets up a binary virtual stream for input from a portal.
Example 8 – Constructing a binary virtual stream for input from a portal
RWPortalStreambuf buf(portal);
RWbistream istrm(&buf);
Creating Chains of Objects
When creating an instance of a Rogue Wave virtual stream, such as an RWpostream, you will usually use a low-level construct, such as an RWSocket. In many cases, you will need to build some intermediate objects before creating the virtual stream. For example, you might create an RWPortal, then an RWPortalStreambuf, and then an RWpostream.