Connecting to the Server
Example 4 connects an application to a server using an RWHttpClient. It initializes the RWHttpClient object and specifies the HTTP server to connect to.
NOTE: Servers and files shown in the code might not exist and are included as examples only.
Example 4 – Connecting to the server
RWHttpClient client = RWHttpSocketClient::make(); //1
try {
client.connect("www.perforce.com"); //2
} catch (const RWxmsg& msg) {
// error...
}
//1 Initializes the client object by assigning an initialized RWHttpSocketClient object created from the static make function. The RWHttpSocketClient uses an RWSocketPortal internally to communicate with the server. You can create other clients to communicate with the server through another channel (such as over a secure socket).
//2 The client attempts to establish a connection to the server (www.perforce.com). If any errors occur that prevent the client from establishing a connection to the server, an exception is thrown.
RWHttpClient defaults to port 80 on the server specified. If you want to connect to the HTTP server on an alternate port, you can pass an optional argument to the connect method, as shown below.
 
client.connect("www.perforce.com", 8001);
This invocation connects to the HTTP server running on port 8001 of the www.perforce.com server.
RWHttpAgent does not have an explicit connection mechanism because connections to HTTP servers are established automatically as they are needed to fill requests. All RWHttpAgent instances are automatically valid on construction.
 
RWHttpAgent agent;