RWPortal as a Base
As we have mentioned, class RWPortal is an encapsulation of the portal concept, a high-level abstraction used in network programming with Rogue Wave products. Class RWPortal is a base for classes such as
RWSocketPortal,
RWBufferedRecvPortal and
RWBufferedSendPortal, and is used for writing code that sends or receives data over a network connection without regard for a particular networking transport protocol or technology. For example, consider the following function:
void serviceClient(RWPortal& p)
{
RWPortalIStream is(p);
RWPortalOStream os(p);
Request request;
is >> request; // read the client request
Response response(request);
os << response; // send our response
// now process the remaining data on is...
}
Because of the way this code is written, it could be used to service clients of an imaginary server, regardless of the transport protocol used in implementing the server. Of course, a transport protocol must be chosen at some point, but that doesn't mean all networking code must be implemented in a way that is specific to that protocol. By keeping transport protocol details out of the code as much as possible, we increase our chances for code reuse.
In the Essential Networking Module, you would use the high-level class
RWPortal and derived classes such as
RWSocketPortal to write most of your code. These classes are discussed in
Chapter 4, Portals. To make custom modifications to your network connections, you would then work with lower level classes such as
RWSocket, which is described in
Chapter 7, The Berkeley Sockets Adapter, and
Chapter 8, The Windows Socket Adapter.