/** * @brief http server thread * @param arg: pointer on argument(not used here) * @retval None */ static void http_server_netconn_thread(void *arg) { struct netconn *conn, *newconn; err_t err, accept_err; /* Create a new TCP connection handle */ conn = netconn_new(NETCONN_TCP); if (conn!= NULL) { /* Bind to port 80 (HTTP) with default IP address */ err = netconn_bind(conn, NULL, 80); if (err == ERR_OK) { /* Put the connection into LISTEN state */ netconn_listen(conn); while(1) { /* accept any icoming connection */ accept_err = netconn_accept(conn, &newconn); if(accept_err == ERR_OK) { /* serve connection */ http_server_serve(newconn); /* delete connection */ netconn_delete(newconn); } } } } }
/** * @brief http server thread * @param arg: pointer on argument(not used here) * @retval None */ static void http_server_socket_thread(void *arg) { int sock, newconn, size; struct sockaddr_in address, remotehost; /* create a TCP socket */ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("can not create socket"); return; } /* bind to port 80 at any interface */ address.sin_family = AF_INET; address.sin_port = htons(80); address.sin_addr.s_addr = INADDR_ANY; if (bind(sock, (struct sockaddr *)&address, sizeof (address)) < 0) { printf("can not bind socket"); return; } /* listen for incoming connections (TCP listen backlog = 5) */ listen(sock, 5); size = sizeof(remotehost); while (1) { newconn = accept(sock, (struct sockaddr *)&remotehost, (socklen_t *)&size); http_server_serve(newconn); } }