Writing a Client Program That Uses RWSecureSocket
Example 1 is a client program that creates a secure socket and sends a message.
This example uses utility functions provided in util.h.
Example 1 – Client program that uses RWSecureSocket
// File: examples\secsock\manual\RWSecureSocketSimpleClient.cpp
#include <rw/network/RWWinSockInfo.h>
#include <rw/network/RWInetAddr.h>
#include <rw/secsock/RWSecureSocketPackageInit.h>
#include <rw/secsock/RWSecureSocketContext.h>
#include <rw/secsock/RWSecureSocket.h>
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
#include <secsockexampledefs.h>
include <util.h>
int main(int argc, char **argv)
{
try {
RWWinSockInfo info; //1
RWSecureSocketPackageInit secsockInit; //2
#if defined(RW_SECSOCK_RNG_NEEDS_SEEDING)
RWSecureSocketPackageInit::seedRNGFromFile
(SEED_DATA_FILE); //3
#endif
int port = parseClientCommandLine(argc, argv);
RWSecureSocketContext context; //4
context.prepareToAuthenticate(TRUSTED_CERTS_FILE); //5
RWInetAddr addr(port, “localhost”) //6
RWSecureSocket sock(context); //7
sock.connect(addr); //8
sock.sendAtLeast("Hello World!"); //9
sock.close(); //10
} catch(const RWInternalErr& ie) {
cerr << ie.why() << endl;
return 1;
} catch(const RWExternalErr& ee) {
cerr << ee.why() << endl;
return 1;
}
return 0;
} //11