14 if (
stat(path, &st) == 0 && (fp = fopen(path,
"rb")) != NULL) {
15 mg_printf(conn,
"--w00t\r\nContent-Type: image/jpeg\r\n" 16 "Content-Length: %lu\r\n\r\n", (
unsigned long) st.st_size);
17 while ((n =
fread(buf, 1,
sizeof(buf), fp)) > 0) {
31 const char **file_names = (
const char **) conn->
server_param;
33 time_t
now = time(NULL);
41 if (strcmp(conn->
uri,
"/stream") != 0) {
44 "Go to <a href=/stream>/stream</a> for MJPG stream");
49 "HTTP/1.0 200 OK\r\n" "Cache-Control: no-cache\r\n" 50 "Pragma: no-cache\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\n" 51 "Connection: close\r\nContent-Type: multipart/x-mixed-replace; " 52 "boundary=--w00t\r\n\r\n");
58 state->file_index = 1;
59 state->last_poll = time(NULL);
66 if (file_names[
state->file_index] != NULL) {
69 if (file_names[
state->file_index] == NULL) {
87 int main(
int argc,
char *argv[]) {
91 printf(
"Usage: %s image1.jpg image2.jpg ...\n", argv[0]);
void mg_send_header(struct mg_connection *c, const char *name, const char *v)
int stat(const char *path, struct stat *buffer)
struct mg_server * mg_create_server(void *server_data, mg_handler_t handler)
const char * mg_get_option(const struct mg_server *server, const char *name)
if(strcmp(arg,"1305")!=0)
size_t mg_write(struct mg_connection *c, const void *buf, size_t len)
time_t mg_poll_server(struct mg_server *server, int milliseconds)
size_t mg_printf_data(struct mg_connection *c, const char *fmt,...)
static struct mg_server * server
int main(int argc, char *argv[])
static void send_file(struct mg_connection *conn, const char *path)
static int ev_handler(struct mg_connection *conn, enum mg_event ev)
const char * mg_set_option(struct mg_server *server, const char *name, const char *value)
size_t mg_printf(struct mg_connection *conn, const char *fmt,...)
void mg_destroy_server(struct mg_server **server)