
#include <iostream>
using namespace std;
#include "Client.h"

#include<ctime>


//header file containing the class definition

/*--------------------- Client Constructor ---------*/
	Client::Client( char IPAddress[],int Port_Number): Client_Server()//takes two arguments
	{
			is_server = false;//used to determine action taken in the destructor
			their_addr.sin_family = AF_INET;    //Settin the Address family  
			their_addr.sin_port = htons(Port_Number);  //Port number
			their_addr.sin_addr.s_addr = inet_addr(IPAddress);
			//This is where the IP Address is placed in the struct the 
		    memset(&(their_addr.sin_zero), '\0', 8);  // zero the rest of the struct

			if(connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1)
			//Connect to the Address and port number specified in the sockaddr_in their_addr struct
			{
				cout <<"Could not connect to socket." << endl;
				exit(1);
			}
			else
			{
			global_socket = sockfd;//so can use generic function calls for both server and client
			//send and recieve methods.
			}
		
	}


/*---------------------- End Client Constructor ------------------------------*/
	/*------------------- Destructor --------------------------------------*/
	/*Client::~Client()
	//This is the destructor which ties up all the 
	{
		//Client_Server::~Client_Server();
		
	}*/
/*--------------------End of Destructor--------------------------*/



	//--- checks whether the server or client is called
	//is used to determine the actions taken in the destructor
	bool Client::isServer()
	{
		if(Client_Server::isServer())
			return true;
		else
			return false;
		
	}//end 
	


	//---- Sends data using the socket options, uses socket variable global socket.
	bool Client::send_data(char msg[])
	{
		if(Client_Server::send_data(msg))
			return true;
		else
			return false;
	}//end send_data(char msg[])
	

	//---- Receives data using the socket calls
	bool Client::recv_data()
	{
		if(Client_Server::recv_data())
			return true;
		else
			return false;
	}//end receive data

	char * Client::getRecvData()
	{
		return (Client_Server::getRecvData());
		
	}

