Very first request please use CODE tags
Code:
n = read(newsockfd,buffer,1024);/*read from client*/
if (n < 0) perror("\n ERROR reading from socket \n");/*check for errors*/
Why do you continue here even after an error ? ( after perror )
Do you want to continue even when n == 0
Code:
if(k==0)
break;
break;
Does that mean to break irrespective of the value of ' k '. Then why is that part of the code ? Anything specific here ?
Code:
if(j==0)
{
close(newsockfd);
close(sockfd);
exit(0);
}
Parent not waiting for the child to complete
Code:
write(newsockfd,"\n Client wrote",14);/*write to client*/
Flusing before writing and not after that.
Code:
n=write(newsockfd,buffer,sizeof(buffer));/*write to client*/
if(n<0)perror("Write Failed");
}
The same pattern where it continues processing even after write call returns a negative value
Code:
gets(buf);
This function would not check any buffer overrun.
try to use fgets.
|