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...
}
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;