回复:这个客户端<->服务器(foodrequest-foodinfo 场景)我正在尝试将接收发送到成功的客户端-服务器连接 sock_fd。在这个循环中,我收到了第一个信息,但下一次迭代在键盘输入处停止,即 readInFood()。我处理缓冲区的方式有什么问题吗?或其他。
RESPONSE_BUFFER = 2200;
INPUT_BUFFER = 100;
int numbytes;
char foodType[INPUT_BUFFER];
char foodResponse[RESPONSE_BUFFER];
do {
//send a message to server
if (send(sock_fd, readInFood(foodType), INPUT_BUFFER, 0) == -1)
perror("send");
//receive the message
if ((numbytes = read(sock_fd, foodResponse, RESPONSE_BUFFER)) == -1) {
perror("receive");
exit(EXIT_FAILURE);
}
//end the buffer string
foodResponse[numbytes] = '\0';
//print the buffer
printf("\nThis is the information you require: %s", foodResponse);
} while (foodType[0] != 'q' || foodType[0] != 'Q');