Go to the documentation of this file.00001 #include "mongoose.h"
00002
00003
00004
00005 static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
00006 if (ev == MG_REQUEST) {
00007 mg_send_header(conn, "Content-Type", "text/plain");
00008 mg_printf_data(conn, "This is a reply from server instance # %s",
00009 (char *) conn->server_param);
00010 return MG_TRUE;
00011 } else if (ev == MG_AUTH) {
00012 return MG_TRUE;
00013 } else {
00014 return MG_FALSE;
00015 }
00016 }
00017
00018 static void *serve(void *server) {
00019 for (;;) mg_poll_server((struct mg_server *) server, 1000);
00020 return NULL;
00021 }
00022
00023 int main(void) {
00024 struct mg_server *server1, *server2;
00025
00026 server1 = mg_create_server((void *) "1", ev_handler);
00027 server2 = mg_create_server((void *) "2", ev_handler);
00028
00029
00030 mg_set_option(server1, "listening_port", "8080");
00031 mg_copy_listeners(server1, server2);
00032
00033
00034
00035 mg_start_thread(serve, server1);
00036 mg_start_thread(serve, server2);
00037 getchar();
00038
00039 return 0;
00040 }