I am trying to make a server in C. After receiving the client connection the purpose is to wait for client information on the socket, for this I use the following code.
/*Read Messages*/
close(fd);
nread = read(fd, msg, BUFFERSIZE-1);
close(fd);
msg[nread] = '/*Read Messages*/
close(fd);
nread = read(fd, msg, BUFFERSIZE-1);
close(fd);
msg[nread] = '%pre%';
printf("%s\n", msg);
';
printf("%s\n", msg);
The close(fd)
function will close / clear the socket before reading.
But the problem happens in reading, read()
. My question is if the close(fd)
are set correctly and if this is the consequence of read
read garbage.