Im having trouble where my client wont output whats in the buffer (character array) until it receives another message from the server.
The server appends this 2nd message to the 1st, so it appears to be putting the message into the server buffer and not sending it, then sending it when the next message is sent.
MSGGET function:
Code
if(strcmp(tmpInput,"MSGGET\n") == 0)
{
if(totnumMessages > 0) //There must be at least 1 message in order to send a message back
{
inFile.open("MessageOfTheDay.txt");
if( !inFile ) { // file couldn't be opened
cout << "Error: file could not be opened" << endl;
}
cout << tmpInput;
/*convert c++ string from array back to c-string in order to send to client*/
while(inFile)
{
getline (inFile, line);
if (lineno == currentOutMessage)
{
tmpString = line;
strcpy(tmpMsg, tmpString.c_str());
send (childSocket, tmpMsg, strlen(tmpMsg) + 1, 0);
memset(&tmpMsg[0], 0, sizeof(tmpMsg));
}
lineno++;
}
inFile.close();
if(currentOutMessage == (totnumMessages-1)) //Loop through messages
{
currentOutMessage = 0;
}
else
{
currentOutMessage++;
}
}
else
{
strcpy(tmpMsg,"There are currently no messages.\n");
send (childSocket, tmpMsg, strlen(tmpMsg) + 1, 0);
memset(&tmpMsg[0], 0, sizeof(tmpMsg));
}
Client print method:
Code
if (recv(s, buf, sizeof(buf), 0) > 0) {
cout << buf;
memset(&buf[0], 0, sizeof(buf));
}