IP Sockets Project for University

Hi There all

I am developing an IP sockets program for my final year Bsc (Hons) in Computing & Networks which is going to be used for the university robot project. I have the IP sockets program working and now I am trying to add some additions functions to the program which allows me to measure network performance related tests over a (LAN).

The tests will include sending/echoing bytes a number of bytes to the server and back. The tests will also need to show the time of how long it took to send & receive the message from the client & server respectively, the timing has to be measure milliseconds and to be able to calculate the the elasped time. The project needs to be in for the 28th August and I am not having much luck with it need all the assistance I can get, not a great programmer on C.

I have enclosed some coding below to show what the program currently looks like at the moment, This also includes my attempts of measuring the time when a message is received by the server, and my attempts to show the number of bytes sent. I desperately need help, any small piece of info you may have just might mke the difference. The coding is shown below for the client coding, this might take a little while to read.

Client Coding:


#include "mySocket.h"
#include "myLog.h"
#include "myException.h"
#include "myHostInfo.h"
#include <string.h>
//#include "PerfTimer.h"
#include <Windows.h>
#include <Time.h>
//#include <afxwin.h>


myLog winLog;
void readServerConfig(string&);
void checkFileExistence(const string&);

int main()
{
// Initialize the winsock library
myTcpSocket::initialize();
// LARGE_INTEGER *lpPerformanceCount = (LARGE_INTEGER) new (sizeof
(LARGE_INTEGER));
LARGE_INTEGER lpPerformanceCount ;
// u_char cTTL
// CString str;




// get client's information (assume neither the name nor the address is given)
winLog << endl;
winLog << "Retrieve the localHost [CLIENT] name and address:" << endl;
myHostInfo clientInfo;
string clientName = clientInfo.getHostName();
string clientIPAddress = clientInfo.getHostIPAddress();
std::cout << "Name: " << clientName << endl;
std::cout << "Address: " << clientIPAddress << endl;
winLog << " ==> Name: " << clientName << endl;
winLog << " ==> Address: " << clientIPAddress << endl;

// get server's IP address and name
string serverIPAddress = "";
readServerConfig(serverIPAddress);
winLog << endl;
winLog << "Retrieve the remoteHost [SERVER] name and address:" << endl;
winLog << " ==> the given address is " << serverIPAddress << endl;

myHostInfo serverInfo(serverIPAddress,ADDRESS);
string serverName = serverInfo.getHostName();
std::cout << "Name: " << serverName << endl;
std::cout << "Address: " << serverIPAddress << endl;
winLog << " ==> Name: " << serverName << endl;
winLog << " ==> Address: " << serverIPAddress << endl;

// create the socket for client
myTcpSocket myClient(PORTNUM);
std::cout << myClient;
winLog << "client configuation: " << endl;
winLog << myClient;

// connect to the server.
std::cout << "connecting to the server [" << serverName << "] ... " << endl;
winLog << "connecting to the server [" << serverName << "] ... " << endl;
myClient.connectToServer(serverIPAddress,ADDRESS);

int recvBytes = 0;

while (1)
{
// send message to server
char messageToServer[MAX_MSG_LEN+1]= "hello world2";
//char senddata(socketId,buf,MAX_MSG_LENGTH,0);
//memset(messageToServer,0,sizeof(messageToServer));
std::cout << "[SEND] ";
std::cin.getline(messageToServer,MAX_MSG_LEN);
//memset(messageToServer,0,sizeof(senddata));
std::cout << " %s [%s]with %d bytes of data:";
std::cout << strlen(messageToServer);


//###########################################

char tmpbuf[128], timebuf[26];
time_t ltime;
string mystr;
mystr="ABC";
// time( &ltime );
QueryPerformanceCounter( &lpPerformanceCount);
std::cout<<( "Time in something:=%ldms,TTL=%d", &lpPerformanceCount);
//Removing getline so we that we don't need to wait for input //std::cin.getline
// (messageToServer,MAX_MSG_LEN);




//###########################################


winLog << "[SEND] " << mystr << endl;
myClient.sendMessage(mystr);
if ( !string(messageToServer).compare("Quit") || !string
(messageToServer).compare("quit") )
break;

// receive message from server
string messageFromServer = "";
recvBytes = myClient.recieveMessage(messageFromServer);
if ( recvBytes == -99 )
break;

std::cout << "[RECV:" << serverName << "]: " << messageFromServer << endl;
winLog << "[RECV:" << serverName << "]: " << messageFromServer << endl;

}

return 1;
}

void readServerConfig(string& serverIPAddr)
{
serverIPAddr = "127.0.0.1"; //DEBUG 15.02.08
string serverConfigFile = ".\\serverConfig.txt";
//checkFileExistence(serverConfigFile);
//ifstream serverConfig(serverConfigFile.c_str());

// read server's IP address
//getline(serverConfig,serverIPAddr);

//serverConfig.close();
}

void checkFileExistence(const string& fileName)
{
ifstream file(fileName.c_str());
if (!file)
{
std::cout << "Cannot continue:" << fileName << " does NOT exist!" << endl;
exit(1);
}
file.close();
}



GetTickCount() returns a 32-bit integer representing the number of milliseconds since the program was started. GetTickCount64() does the same but returns an ULONGLONG. Whatever that is.
I think ULONGLONG is an unsigned long long int (if those exist).
As far as I can remember, long long is only signed, not unsigned.
Well, it doesn't matter much. I don't think the program will be running for 292277024,66 years, so that extra bit isn't too important.
long long int can be unsigned. Though like you said, the likelihood of the program running for that long is not very high.
Last edited on
Topic archived. No new replies allowed.