ok i am unsure how to do that, i thought i had solved it but obviously not
now added the following files to the code
Code:
// mesagesend.cpp: implementation of the mesagesend class.
//
//////////////////////////////////////////////////////////////////////
#include "mesagesend.h"
#include "connecting.h"
#include <iostream>
#include <winsock2.h>
#include <stdio.h>
using namespace std;
int connecttoserver(unsigned short port, const char *serverName);
void disconnectfromserver(int clientSocket);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
mesagesend::mesagesend()
{
}
mesagesend::~mesagesend()
{
}
void mesagesend::sendmessage()
{
mysocket = connecttoserver(7654, "localhost");
if (mysocket == -1) {
disconnectfromserver(mysocket); //if error occurs shut down client
return;
}
#define message_size 256
char inmessage[message_size];
char outmessage[message_size] = "I sent you this message";
nbytes = send(mysocket, outmessage, sizeof(outmessage), 0);
if (nbytes == SOCKET_ERROR) {
cout << "Message Send Failed!" << endl;
} else {
// print the message we sent
printf("Message Sent : %s\n", outmessage);
}
nbytes = recv(mysocket, inmessage, sizeof(inmessage), 0);
if (nbytes == SOCKET_ERROR) {
cout << "Recv Failed!" << endl;
} else {
// print the received message
printf("Message Received : %s\n", inmessage);
}
disconnectfromserver(mysocket);
printf("Press any key to continue ...\n");
getchar();
}
Code:
// mesagesend.h: interface for the mesagesend class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MESAGESEND_H__FFA5479E_0367_4BB4_A1EA_B313692D5510__INCLUDED_)
#define AFX_MESAGESEND_H__FFA5479E_0367_4BB4_A1EA_B313692D5510__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class mesagesend
{
public:
mesagesend();
virtual ~mesagesend();
void sendmessage();
int mysocket;
int nbytes;
};
#endif // !defined(AFX_MESAGESEND_H__FFA5479E_0367_4BB4_A1EA_B313692D5510__INCLUDED_)
any help is greatfully accepted