/**
 * File: time-client.cc
 * --------------------
 * Implements a client program that connects to a specified time server and prints 
 * out the data that the server sends back.
 * 
 * This program uses read() to read the data sent back from the server.
 */

#include <iostream>
#include <unistd.h>
#include "client-socket.hh"

using namespace std;


int main(int argc, char *argv[]) {
  // Open a connection to the server
  int socketDescriptor = createClientSocket("myth64.stanford.edu", 12345);

  // Read in the data from the server (assumed to be at most 1024 byte string)
  char buf[1024];

  // We'll assume here that read successfully reads all bytes
  int bytesRead = read(socketDescriptor, buf, sizeof(buf));
  buf[bytesRead] = '\0';
  
  close(socketDescriptor);
  cout << buf << endl;

  return 0;
}
