1
Re :이 클라이언트 < -> server (foodrequest-foodinfo 시나리오) 성공적인 클라이언트 - 서버 연결 sock_fd에 수신을 보내려고합니다. 이 루프에서는 첫 번째 정보를 받지만 다음 반복은 키보드 입력, 즉 readInFood()에서 멈 춥니 다. 버퍼를 처리하는 방식에 문제가 있습니까? 그렇지 않으면.C 프로그래밍 소켓 버퍼
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');
우리는'readInFood()'의 정의를 보여줍니다. –
글을 올릴 때 코드를 들여주세요 ... 공백은 당신의 친구입니다 – Mike
저에게 들여다 보입니다. 'perror()'사용에 +1. – Barmar