client.dox 1.17 KB
/** @file
\author Imanol Barba Sabariego
\date 13/06/2013
\page client_code Client
\brief Ejemplo de aplicación cliente

\code{.cpp}
#include "Socket.h"
#include <iostream>
#include "SocketException.h"
#include <sstream>
#include <signal.h>

#include <sys/time.h>
#define PRIVATEKEY "bin/private_client.key"
#define PUBLICKEY "bin/public_client.key"

using namespace std;

void exitClient(int signal)
{
	cout << "Server connection terminated unexpectedly" << endl << "Exiting" << endl;
	exit(-1);
}

void exchangeKeys(Socket &s)
{
	if(!s.receivePublicKey() || !s.sendPublicKey())
	{
		cout << "Error exchanging keys" << endl << "Exiting" << endl;
		s.Close();
		cout << "Socket closed" << endl;
		exit(-1);
	}
	s.recvAES();
	s.sendAES();
}

int main()
{
	signal(SIGPIPE, exitClient);
	Socket s;
	s.loadKeys(PUBLICKEY,PRIVATEKEY);
	string send, recv, host;
	int port;
	s.Create();
	cout << "Created socket" << endl;
	cout << "Hostname: ";
	cin >> host;
	cout << "Port: ";
	cin >> port;
	cin.ignore();
	s.Connect(host,port);
	cout << "Connected" << endl;
	exchangeKeys(s);
	while(true)
	{
		cout << "> ";
		getline(cin,send);
		s >> recv;
		cout << "Received: " << recv << endl;
	}
}
\endcode
*/