I want to build a while loop that continuously reads from a non-blocking socket whether or there are message sent. I use the read function to read from the socket but when ever it gets to read(), the while loop is blocked. Do I also need to make read non-blocking?
while(1){
char client_response[256];
client_response = (char*) malloc(256);
int reader = read(socket_fd, server_response, sizeof(server_response));
printf("passed reader\n"); // this never shows
if(reader < 0){
perror("read fails\n");
return -1;
}
sleep(1);
}