소켓으로 서버 클라이언트 구현 중
f = fork();
for(;;)
{
if(f == 0)
{
gets(buf);
write(x, buf, strlen(buf));
if(strcmp(buf, "exit") == 0) break;
}
else
{
y = read(x, buf, 50);
write(1, buf, y);
printf("\n");
if(strcmp(buf,"exit") == 0) break;
}
close(x);
이런 코드인데
int y;
char buf[50];
y=read(x, buf, 50);
buf[y]=0;
if (state[x] == 1)
{
handle_state1(x, &pset, buf);
state[x]++;
}
else if (state[x] == 2)
{
printf("debug3\n");
handle_state2(x, &pset, buf, &cli);
printf("debug4\n");
state[x] = 3;
printf("debug5\n");
}
else if (state[x] == 3)
{
printf("debug6\n");
handle_state3(x, &pset, socket_num, &buf, &cli);
state[x]++;
}
else if (state[x] == 4) {
handle_state4(x, &pset, socket_num, &buf, &cli);
state[x]++;
}
else if (state[x] == 5) {
handle_state5(x, &pset, &buf, &cli);
}
이런 식으로 서버와 클라이언트를 왔다갔다 하면서 마지막 5까지 도달해야하는데
2번까지 가면 else if에서 무한루프가 걸려버립니다
해결 방법이 없을까요.
코드가 들여쓰기가 안되어 있네요.
코드가 들여쓰기가 안되어 있네요.
읽는 사람이 잘 읽을 수 있을까요?
댓글 달기