Background:
Developing a client - server application communicating over TCP. Therefor, I an using the normal send() and recv() functions. Additionally, packet payloads are encrypted with a custom algorithm. Commands are sent to the server, but the server does not execute the commands immediately, but stores them in a string array and executes them after the socket is closed (Few exceptions).
Program Information:
Linux sockets
g++
Currently single threaded (This will change)
Problem:
When the client is finished communicating with the server it sends a specific command that is essentially a " I am done, will you send me the commands that you received and the hashed values of each command" packet. When the server receives this command (This is one of the exceptions), it sends the list of commands that it received in one packet followed by the hashes in another packet. On the client side, the client notes that the "finish" command has been sent and blocks with recv(). It receives the first packet, in this case the list of commands, and then blocks with yet another recv() [ Note: I currently have this in a loop, but it doesn't work either way]. At this receive however, I get one character and the client crashes [Note: It crashes because it is looking for a substr in a one character string, so this isn't the real problem].
Additional Information:
I know that the server is sending information because wireshark captures the packet with a byte size of 502 [PSH, ACK], the same size for all data packets and the client replies with a [ACK] packet, so hypothetically, it gets the packet. Also, I ran into this problem before and it seemed that placing a usleep(10) between sends worked, but it does not work on this occasion.
The receive and send buffers are cleared with:
Expand|Select|Wrap|Line Numbers
- memset(miscvar, 0x0, LINE_ARRAY_SIZE)
On another note: the recv() recieves more data that is sent, but is cut off at the null character, hence my use of memset.
My thoughts:
I feel as if C++ is racing the stack and recv() before all the data can be sent. I know this isn't true as recv() blocks. I also thought that I wasn't clearing the buffers, but atlas, I am.
--------------------------------------------------------------------------------------------------------------------
Sorry for the anecdote, but I wanted to be as specific as I can under my conditions. If you need to see some part of the code, let me know and I see if I can release it. I apologize ahead of time for any ambiguity.