using namespace std;

#include "clnt_conn.h"

#include <iostream>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

using namespace std;

main(int argc, char *argv[])
{
  int     sd;              /* socket descriptor                   */
  int     n;               /* number of characters read           */
  int     sendsiz;
  int     sendpos;
  char    *toserv ;        /* buffer for data to the server       */
  char    fromserv[1000];  /* buffer for data from the server     */

  if ((sd = clnt_conn("www.cs.unca.edu", (unsigned short) 80)) < 0) {
    cerr << "Unable to connect to www.cs.unca.edu" << endl ;
    exit(1) ;
  }

  toserv = "GET /index.html HTTP/1.0\r\n\r\n" ;
  sendsiz = strlen(toserv) ;
  sendpos = 0 ;
  while (sendpos < sendsiz)
    sendpos += write(sd, &toserv[sendpos], sendsiz-sendpos) ;

  /* Repeatedly read data from socket and write to user's screen. */
  n = read(sd, fromserv, sizeof(fromserv));
  while (n > 0) {
    (void) write(1,fromserv,n);
    n = read(sd, fromserv, sizeof(fromserv));
  }

  /* Close the socket. */
  close(sd);

}
