Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Networking Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

7.5 Using Communication Services with Sockets

The Communication Services Layer cannot use socket objects directly because RWSocket is not derived from RWPortal. The Communication Services Layer can use RWSocketPortal, though, because it is derived from RWPortal. In addition, if a portal is not available, a temporary portal can be used.

Example 14 writes the current date to a socket that is obtained from a legacy C application.

Example 14: Using RWSocketPortal to write into a socket

//1

The socket parameter is of type SOCKET. On most systems, SOCKET is a typedef for integer. It is set by the Networking package to represent the type of a legacy socket. It works for both Windows and UNIX applications.

//2

Constructs an object that wraps the C socket.

//3

Builds a portal to the socket's communication channel. The second argument names the object that closes the socket channel. It is set to Application, which means that the application closes the socket and the RWSocketPortal destructor should not close the socket. If the second argument were set to Portal (the default), then the destructor of the RWSocketPortal would close the socket.

//4

Constructs an output stream that uses the socket as the destination for its byte stream.

//5

Writes the current date into the socket. The default constructor for RWDate builds a temporary object representing today's date.

//6

When the scope of the function exits, the output stream, portal stream, and portal object are all destroyed. Only the original socket descriptor is left in the routine that invoked this function.



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.