How could you make a server send messages to a client using printf or fprintf instead of using a system call to write?
I already made my server and was working sending messages via write, but I would rather use fprintf.
For example, this did not work:
newsockfd = accept(sockfd,(struct sockaddr *) &cli_addr, &clilen);
FILE *fp = fdopen(newsockfd, "w");
fprintf(fp, "test");
fflush(fp);
I have a new problem. When I have only the code above, it works, and I can see it in my browser, however, if I add read (newsockfd, buffer, 255), after that I will see in more detail the message sent to my client.
source
share