#include <stdio.h> main() { int i; printf("Content-type: multipart/x-mixed-replace;boundary=TestBoundary"); for(i = 1; i <= 10; i++) { printf("--TestBoundary"); printf("Content-type: text/plain"); printf("count: %d", i); sleep(1); } printf("--TestBoundary--"); } 이것은 1초마다 숫자가 출력되는 것인데요.. 이것이 한꺼번에 10초지나서 출력되어 버려요.. 원인이 뭔지 고수님 좀 알려주세요.....
출력이 한꺼번에 나오는 것은 표준 출력이 버퍼링되기 때문입니다. printf 뒤에 fflush(stdout) 를 넣거나, 시작할 때 setvbuf 로 버퍼를 끄세요. 또한 헤더와 본문 사이에 빈 줄이 필요하고 boundary 앞에 --를 붙이는 형식도 맞춰야 합니다.