I have a problem with a socket. I have a server and a client.
The purpose of the program:
Client/server connection (both send messages each others) Client sends a message; Server reads the message; Server sends back the message to the client.
But I have a deadlock because both client and server wait for receiving a message. The code:
Server.c
message = "Client connection handler ok\n";
write(sock , message , strlen(message));
message = "type something and i'll repeat what you type \n";
write(sock , message , strlen(message));
//Receive a message from client
while( (read_size = recv(sock , client_message , 2000 , 0)) > 0 )
{
puts(client_message);
//Send the message back to client
write(sock , client_message , strlen(client_message));
bzero(client_message,2000);
}
Client.c
//Here I print the two messages You can see server side code:
//- Client connection handler ok
//- type something and i'll repeat what you type
while( (read_size = recv(sockfd , client_message , 2000 , 0)) > 0 )
{
printf("%s\n",client_message);
bzero(client_message,2000);
}
In the execution of the code I remain blocked in both client and server inside the while.
How can I solve this problem?