i’ve a problem with send/recv: if the client send two strings, server receive the two in only one recv and the second recv attend a third send from the client (that i don’t want to send). I would like to send 2 strings and receive 2 strings. How can i do?
My code:
CLIENT
char login[] = "admin";
char password[] = "admin";
send(sd, login, strlen(login), 0);
send(sd, password, strlen(password), 0);
SERVER:
bzero(login,MAX);
bzero(password,MAX);
recv(sd_client, login, sizeof(login), 0);
recv(sd_client, password, sizeof(password), 0);
TCP cannot send/recv strings. TCP cannot send/recv messages longer than one byte. TCP cannot send/recv structs longer than one byte.
TCP transport is a byte stream.
If you want to transfer anything more complex than one byte, you need an extra protocol on top, hence HTTP, SMTP, etc. etc. protocols.
If you specifically want to send null-terminated strings, for example, you need to buffer and concatenate received data until a null is detected – then you have your ‘C’-style string and can proceed to assemble the next string.
Rgds,
Martin