Let's suppose you want to pass information between C++ applications running on two hosts connected by TCP. The mechanism of choice would be a socket. Figure 1 demonstrates a chain of objects you could build in order to use virtual streams for this purpose.
From an RWSocket, you can create an RWSocketPortal instance. With this portal, you can create an RWPortalIStream. With this istream, you can create an instance of an RWvistream subclass. In this example, we create an endian input stream.
void MyClass::getData(RWSocket s) { RWSocketPortal portal(s); RWPortalIStream istrm(portal); RWeistream eistrm(istrm); eistrm >> data_; }
Note that you cannot read an object from an input stream unless the object was written to its matching output stream. For instance, you cannot write to a vostream, then have another application read the object from a pistream. Also note that, unless data_ is an instance of a Rogue Wave class, you must create helper functions to work with virtual streams. Most Rogue Wave classes include helper functions for virtual streams. The network/distcltn and network/server directories contain excellent examples of creating streams from RWSocketPortal instances.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.