I've been working on a program that sends periodically sends several values at once to another computer, and I've been working on a way for the receiving computer to parse the received data because messages have been concatenating. I did some reading on a way to do this, and in one book I was reading I found a function that used delimiters for parsing messages, and I modified for my program:
The idea of the function is to receive one char at a time, and store the characters in a buffer until it reaches a space, at which point you know that you've read one of the values being sent in a message. The process is repeated and when you've reached the point where you've read three delimiters, you know you've read one complete message, and theoretically, you should be able to move on to the next message.
int ReceiveMessage(SOCKET s, char *buf, int maxLen, char *x, char *y, char *z)
while (delimCount < FIELDSPERMSG)
rv = recv(s, buff, 1, 0);
if (rv < 0)
else if (rv == 0)
if (*(buff) == DELIMCHAR) /* count delimiters */
delimCount += 1;
received += 1;
strcpy ( x, buf);
printf("Server: x position received - %ld.\n", x);
strcpy ( y, buf);
printf("Server: y position received - %ld.\n", y);
For some reason I'm not seeing though, the program seems to be hanging in execution of the function. Any suggestions?