A Simple Code Example
Here is a simple example that combines classes from the networking concepts and networking streams categories to send the traditional “Hello, World!” message over the Internet:
 
#include <rw/rstream.h>
#include <rw/network/RWSocketPortal.h>
#include <rw/network/RWInetAddr.h>
#include <rw/network/RWWinSockInfo.h>
#include <rw/network/RWPortalOStream.h>
 
int main()
{
RWWinSockInfo info; // 1
RWSocketPortal p(RWInetAddr(3010,"net.roguewave.com")); // 2
RWPortalOStream ostrm(p); // 3
ostrm << "Hello, World!" << endl; // 4
return 0;
}
On //1, the code initializes the Winsock DLL to make the example portable to Windows; this has no effect on UNIX. In //2 through //4, the code then constructs a socket portal as its access point to the communication stream, constructs an output stream using that socket portal as a parameter, and sends the message through the output stream over the network.
Overall, the example demonstrates how the Essential Networking Module encapsulates low-level programming details within an intuitive C++ interface. In a straightforward way, you can open and close connections, send and receive data, and perform virtually all aspects of network programming using the Essential Networking Module.