hey guys! im struggling for the past couple of days with a socket problem.
im trying to master the basics in order to proceed and integrate this mechanism in my program which is supposed to run on a server.
basically the problem is weird and there's couple of parts to it that i quite cant understand, mainly in the client program.
in my client code i run an infinite while loop with 1 send() and 1 recv() - straightforward and simple; server is supposed to recv() and send() back to the client a string.
but here's what bothers me:
first of all when running client - the server receives only the first message; after that the strings wont be sent..
second - the while loop that is supposed to be infinite - terminates after 3 iterations..
any help related to this issue would be appreciatedCode:
int main (int argc, char **argv)
struct sockaddr_in cudaserver;
unsigned int cudalen;
int received = 0;
if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
Die("Failed to create socket");
memset(&cudaserver, 0, sizeof(cudaserver));
cudaserver.sin_family = AF_INET;
cudaserver.sin_addr.s_addr = inet_addr(argv);
cudaserver.sin_port = htons(atoi(argv));
while (connect(sock,(struct sockaddr *) &cudaserver,sizeof(cudaserver)) < 0)
Die("Failed to connect with server");
printf("input the word to send to server\n");
cudalen = strlen(buffer);
if (send(sock, buffer, cudalen, 0) != cudalen)
Die("Mismatch in number of sent bytes");
while (received > 0)
int bytes = 0;
if ((bytes = recv(sock, buffer, BUFFSIZE-1, 0)) < 1)
Die("Failed to receive bytes from server");
received += bytes;
buffer[bytes] = '\0';
P.S. btw, gdb says that "Program received signal SIGPIPE, Broken pipe." (if that helps anyhow)