When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
4 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
void handle_request(int msgsock) {
///////////////////
// This initial code reads a single message (and ignores it!)
char buffer[MAXDATASIZE];
int num_read = 0;
//read a message from the client
num_read = read(msgsock, buffer, MAXDATASIZE - 1);
printf("read a message %d bytes: %s\n", num_read, buffer);
// TODO: write a function to reply to all incoming messages
// while the connection remains open
// Respond to client:
while (num_read > 0)
{
printf("Received message from client: %s\n", buffer);
if (send(msgsock, buffer, num_read, 0) < 0)
{
perror("Error sending message");
break;
}
}
// Closing the socket:
close(msgsock);
///////////////////
}
@daring oar
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
!close