I have a basic TCP client/server program.
I have a method in both the client and the server that reads and writes. It works perfectly the first time I run it, but when it runs again (it's in a loop) it doesn't read anything in.
void printout(int newsockfd, char buffer) {
n = write(newsockfd, a2, 256);
n = write(newsockfd, a3, 256);
n = write(newsockfd, a4, 256);
n = write(newsockfd, a5, 256);
n = write(newsockfd, a6, 256);
}
in the server
void printout(char buffer[], int sockfd) {
bzero(buffer, 256);
n = read(sockfd, buffer, 256);
printf("%s\n", buffer);
n = read(sockfd, buffer, 256);
printf("%s\n", buffer);
n = read(sockfd, buffer, 256);
printf("%s\n", buffer);
n = read(sockfd, buffer, 256);
printf("%s\n", buffer);
n = read(sockfd, buffer, 256);
printf("%s\n", buffer);
}
a2, a3, a4, a5, and a6 are strings. The first time it runs it prints everything properly. The second time, it prints out nothing, just a bunch of blank lines. When I tested to find out what buffer was, I got that its " ". Do you know what the problem is or how I can fix it?