Ok, I think I might have found the problem with sending the data. If I send a string of hex with a 0x00 as one of the bytes, it stops receiving the rest. Well, when I say it stops receiving it, I can't see it. Here's an example. The client sends this buffer:
buf[0] = 0x21;
buf[1] = 0x00;
buf[2] = 0x21;
buf[3] = 0x21;
buf[4] = 0x21;
buf[5] = 0x21;
What I expect to see at the server end is "! !!!!" (that's one exclamation mark followed by a space followed by four exclamation marks). However, the server just prints one exclamation mark. I don't know whether that's because it stops reading after the 0x00, or just doesn't print anything after it. Here's the code which receives the data:
memset(line, 0x00, LINE_ARRAY_SIZE);
while (recv(connectSocket, line, MAX_MSG, 0) > 0) {
cout << " -- " << line << "\n";
// Convert line to upper case.
for (i = 0; line != '\0'; i++)
line = toupper(line);
// Send converted line back to client.
if (send(connectSocket, line, strlen(line) + 1, 0) < 0)
cerr << "Error: cannot send modified data";
memset(line, 0x00, LINE_ARRAY_SIZE); // set line to all zeroes
}
I thought it might be something to do with the for loop, which seems to stop if the character it's checking is zero, but this occurs after the character is sent to cout.
Edit -
In fact I have now changed the receive routine to this:
memset(line, 0x00, LINE_ARRAY_SIZE);
while (recv(connectSocket, line, MAX_MSG, 0) > 0) {
cout << " -- " << line << "\n";
memset(line, 0x00, LINE_ARRAY_SIZE); // set line to all zeroes
}
I really can't see what is stopping the characters after 0x00 being printed, so I can only assume they're not being sent, or are being discarded by the server. Any help really, really appreciated guys! :-)
--
moto