these are the other files in the project where the functions are located
Code:
// connect.cpp: implementation of the connect class.
//
//////////////////////////////////////////////////////////////////////
#include "connect.h"
#include <winsock2.h>
#include <stdio.h>
#include <iostream>
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
clientconnect::clientconnect()
{
}
clientconnect::~clientconnect()
{
}
int clientconnect::cconnect(unsigned short port, const char *serverName)
{
int error;
WSAData wsaData; // the winsock data structure
if ((error = WSAStartup(MAKEWORD(2, 2), &wsaData)) == SOCKET_ERROR) {
cout << "Winsock Start Up Failed!" << endl; // startup winsock
return -1;
}
int mySocket = socket(AF_INET, SOCK_STREAM, 0); // create my socket
if (mySocket == SOCKET_ERROR) {
cout << "Error Opening Socket!" << endl; // make sure nothing bad happened
return -1;
}
struct hostent *host_entry;
if ((host_entry = gethostbyname(serverName)) == NULL) { // setup the host entry
cout << "Could not find host!" << endl;
}
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_port = htons(port); // fill in the server socket info
server.sin_addr.s_addr = *(unsigned long*) host_entry->h_addr;
if (connect(mySocket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) { // connect to the server
cout<< "Error connecting to server!" << endl;
}
cout << "Connection Established" << endl;
return mySocket;
}
Code:
// connect.h: interface for the connect class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CONNECT_H__28EC6D89_71B9_4440_BA46_68B4136030B6__INCLUDED_)
#define AFX_CONNECT_H__28EC6D89_71B9_4440_BA46_68B4136030B6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class clientconnect
{
public:
clientconnect();
virtual ~clientconnect();
int cconnect(unsigned short port, const char *serverName);
};
#endif // !defined(AFX_CONNECT_H__28EC6D89_71B9_4440_BA46_68B4136030B6__INCLUDED_)
Code:
// disconnect.cpp: implementation of the disconnect class.
//
//////////////////////////////////////////////////////////////////////
#include "disconnect.h"
#include <winsock2.h>
#include <stdio.h>
#include <iostream>
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
disconnect::disconnect()
{
}
disconnect::~disconnect()
{
}
void disconnect::shutdownClient(int clientSocket)
{
closesocket(clientSocket); // close socket
WSACleanup(); // shut down winsock
cout <<"Connection Closed" << endl;
}
Code:
// disconnect.h: interface for the disconnect class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_DISCONNECT_H__FC333D22_2437_41E8_99F1_80BCB68C371F__INCLUDED_)
#define AFX_DISCONNECT_H__FC333D22_2437_41E8_99F1_80BCB68C371F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class disconnect
{
public:
disconnect();
virtual ~disconnect();
void shutdownClient(int clientSocket);
};
#endif // !defined(AFX_DISCONNECT_H__FC333D22_2437_41E8_99F1_80BCB68C371F__INCLUDED_)