This is my code, I want to be able to keep receiving data while I can send data, so I used fork(). But for some reason it is not working, it will only recv once. I am new to network programming, please help.
Code:
char buf[10000];
pid_t pid;
pid = fork();
if(pid == 0)
{
while(1)
{
sleep(1);
memset(buf, '\0', sizeof(buf));
recv(clntSock, buf, sizeof(buf), 0);
printf("%s", buf);
}
}
else
{
while(1)
{
sleep(1);
memset(buf, '\0', sizeof(buf));
fgets(buf, sizeof(buf), stdin);
buf[strlen(buf) - 1] = '\0';
send(clntSock, buf, strlen(buf), 0);
}
}
Foxyy