클라이언트에서 서버로 보낸 명령을 해석하는 프로그램을 만들려고합니다. 내 문제는 내가 명령의 첫 단어 만 읽을 수 있다는 것이다.scanf로 문구 읽기
dict.h
typedef struct
{
pid_t pid_cliente;
int status;
char command[TAM_MAX];
char secure[TAM_MAX];
char password[TAM_MAX];
int client_type;
} request;
클라이언트 측
printf("[ADMIN]: ");
scanf("%s[^\n]", buffer); //reads command
printf("Sending -> '%s'\n", buffer);
strcpy(request.command, buffer, MAX_SIZE-1) //MAX_SIZE = 50
write(server_fifo, & request, sizeof(request));
서버 측
read_res = read(server_fifo, & request, sizeof(request));
if (read_res < sizeof(request))
{
if (!strncasecmp("exit",(char *) & request,4)) return;
else
{
fprintf(stderr, "\nMessage Error!");
return;
}
}
token = strtok(request.command, " "); //reads command
printf("Command -> '%s'\n", token)
..
interprets wich command to do
..
token = strtok(NULL, " "); //reads command argument
printf("Argument -> '%s'\n", token);
입력 :
addcity lisbon
출력 : 아니다
Sending -> addcity
Sending -> lisbon
Command -> addcity
Argument -> (NULL)
어떻게 보내고 실제 통화를주고, 클라이언트와 서버 사이의 명령을하시기 바랍니다받을 않습니다 .. – VoidPointer
, 그 – xRed
이 read''의 반환 값을 확인 미안하고 write' 호출합니다. 송수신 된 바이트 수를 의미합니다. 일치하지 않으면 필요한 모든 바이트를 수신 할 때까지 읽습니다. 수신 된 문자열에'NULL'을 덧붙여 그것을 확인하십시오 .. 더 명확하게하기 위해'요청'구조체 선언을 제공하십시오. – VoidPointer