Skip to content

Instantly share code, notes, and snippets.

@j2doll
Created August 12, 2017 09:11
Show Gist options
  • Save j2doll/ec3b190dcb7b186071fce437dab46e10 to your computer and use it in GitHub Desktop.
Save j2doll/ec3b190dcb7b186071fce437dab46e10 to your computer and use it in GitHub Desktop.
SimpleClient
// SimpleClient.cpp
#include "ace/ACE.h"
#include "ace/INET_Addr.h"
#include "ace/SOCK_Connector.h"
#include "ace/SOCK_Stream.h"
int main()
{
const char* pathname = "index.html";
const char* server_name = "www.adobe.com";
ACE_SOCK_Connector connector;
ACE_SOCK_Stream peer;
ACE_INET_Addr peer_addr;
// set address
peer_addr.set( 80, server_name );
// connect
connector.connect( peer, peer_addr );
char buf[1024];
iovec iov[3];
iov[0].iov_base = (void*) "GET";
iov[0].iov_len = 4; // G E T null
iov[1].iov_base = (void*) pathname;
iov[1].iov_len = strlen(pathname); // + 1 ;
iov[2].iov_base = (void*) " HTTP/1.0\r\n\r\n";
iov[2].iov_len = 13 ;
peer.sendv_n( iov, 3 );
ssize_t n = 0;
// do {
n = peer.recv( buf, 1023 ); // receive buffer
buf[n] = 0;
ACE::write_n( ACE_STDOUT, buf, 1023 ); // print
// } while( n != 0 );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment