Writing a Simple Client
Example 1 connects to a TCP/IP server, and then writes a message to the server. If this code does not run for you, read the next section, which gives an example of error handling.
Example 1 – Writing a simple client
#include <rw/rstream.h>
#include <rw/network/RWSocketPortal.h> //1
#include <rw/network/RWInetAddr.h> //2
#include <rw/network/RWWinSockInfo.h> //3
int main()
{
RWWinSockInfo info; //4
RWSocketPortal p( RWInetAddr(3010,"net.roguewave.com") ); //5
p.sendAtLeast("Hello out there!"); //6
return 0;
}
This example does not use
RWPortal. Instead, it uses an
RWPortal subclass,
RWSocketPortal. Aside from the constructor, this example uses only member functions from the base class
RWPortal. For more information about the relationship between
RWPortal and
RWSocketPortal, see
Understanding the Portal and Implementation Classes. Most everything you learn about
RWSocketPortal also applies to
RWPortal.