Can we see the client.h and client.cpp code?
Here you go:
Client.h:
//===================================
//==== Assignment 3 =================
//==== Damien Parsons - 20830730 ====
//==== Date - 25/03/2011 ============
//==== Client.h =====================
//===================================
#pragma once
#include "stdafx.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include "iostream"
#include "windows.h"
#include "Comms.h"
//======================================================
class ClientConnectException: public exception {
public:
virtual const char* what() const throw() {
return "Client: connect() - Failed to connect.";
}
};
//======================================================
class ClientSocketException: public exception {
public:
virtual const char* what() const throw() {
return "Error at socket()";
}
};
//======================================================
class ClientException: public exception {
public:
virtual const char* what() const throw() {
return "Client: error %ld. ";
}
};
//======================================================
class Client:
public Comms
{
public:
Client(void);
~Client(void);
char Enter();
int Connect();
char receiveBuffer[200];
SOCKET clientSocket;
ClientConnectException noConnection;
ClientSocketException noSocket;
ClientException cException;
};
//======================================================
and client.cpp:
//===================================
//==== Assignment 3 =================
//==== Damien Parsons - 20830730 ====
//==== Date - 25/03/2011 ============
//==== Client.cpp ===================
//===================================
#include "StdAfx.h"
#include "Client.h"
//*************************************************
Client::Client(void){
char receiveBuffer[200] = "";
}
//*************************************************
Client::~Client(void){
}
//*************************************************
int Client::Connect() throw(ClientConnectException,ClientSocketException){
cout<<"\n\n"<<endl;
cout<<"\t\t=================="<<endl;
cout<<"\t\t------CLIENT------"<<endl;
cout<<"\t\t=================="<<endl;
cout<<"\n\n"<<endl;
this->createMySocket();
clientSocket = INVALID_SOCKET;
clientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (clientSocket== INVALID_SOCKET){
throw noSocket;
cout << WSAGetLastError() << endl;
WSACleanup();
return 0;
}
else{
cout << "socket() is OK!" << endl;
}
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr("127.0.0.1");
clientService.sin_port = htons(port);
if (connect(clientSocket, (SOCKADDR*)&clientService, sizeof(clientService)) == SOCKET_ERROR) {
throw noConnection;
WSACleanup();
return 0;
}
else{
cout << "Client: connect() is OK." << endl;
cout << …