Hello,
I am making simple program for communication with API and I have little problem with recv. After sending login and password everything is fine but I must use 2 times recv from socket to get a number of bytes received. I paste some code.
word = "/login";
ilen[0] = (char)strlen(word);
send(fdSock, ilen, 1, 0);
send(fdSock, word, strlen(word), 0);
word = "=name=";
wordtosend = (char*)malloc(strlen(word) + strlen(user) + 1);
strcpy(wordtosend, word);
strcat(wordtosend, user);
ilen[0] = (char)strlen(wordtosend);
send(fdSock, ilen, 1, 0);
send(fdSock, wordtosend, strlen(wordtosend), 0);
word = "=response=00";
wordtosend = (char*)realloc(wordtosend, strlen(word) + strlen(szMD5PasswordToSend) + 1);
strcpy(wordtosend, word);
strcat(wordtosend, szMD5PasswordToSend);
ilen[0] = (char)strlen(wordtosend);
send(fdSock, ilen, 1, 0);
send(fdSock, wordtosend, strlen(wordtosend), 0);
ilen[0] = (char)strlen(cNull);
send(fdSock, ilen, 1, 0);
send(fdSock, cNull, strlen(cNull), 0);
//recv(fdSock, &fs, 1 ,0);
recv(fdSock, &fs, 1 ,0);
bytes = recv(fdSock, sz, (int)fs, 0);
sz[bytes] = '\0';
printf("%s\n", sz);
Without commented recv I get 0. After doing it second time I get correct number of bytes.
Could u help me? Thx.