mirror of
https://github.com/lammertb/libhttp.git
synced 2025-07-31 08:24:23 +03:00
Websocket example should show creation and deletion of websocket connections
This commit is contained in:
@ -73,6 +73,7 @@ void websocket_ready_handler(struct mg_connection *conn) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("\nNew websocket attached: %08x:%u\n", rq->remote_ip, rq->remote_port);
|
||||||
pthread_mutex_unlock(&sMutex);
|
pthread_mutex_unlock(&sMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +88,7 @@ static void websocket_done(tWebSockInfo * wsock) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("\nClose websocket attached: %08x:%u\n", mg_get_request_info(wsock->conn)->remote_ip, mg_get_request_info(wsock->conn)->remote_port);
|
||||||
free(wsock);
|
free(wsock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,8 +187,8 @@ void websock_send_broadcast(const char * data, int data_len) {
|
|||||||
if (data_len<=256) {
|
if (data_len<=256) {
|
||||||
strcpy(buffer, "msg ");
|
strcpy(buffer, "msg ");
|
||||||
memcpy(buffer+4, data, data_len);
|
memcpy(buffer+4, data, data_len);
|
||||||
|
|
||||||
pthread_mutex_lock(&sMutex);
|
pthread_mutex_lock(&sMutex);
|
||||||
send_to_all_websockets(buffer, data_len+4);
|
send_to_all_websockets(buffer, data_len+4);
|
||||||
pthread_mutex_unlock(&sMutex);
|
pthread_mutex_unlock(&sMutex);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ int main(void)
|
|||||||
"document_root", "../../examples/websocket",
|
"document_root", "../../examples/websocket",
|
||||||
|
|
||||||
/* port: use http standard to match websocket url in websock.htm: ws://127.0.0.1/MyWebSock */
|
/* port: use http standard to match websocket url in websock.htm: ws://127.0.0.1/MyWebSock */
|
||||||
/* if the port is changed here, it needs to be changed in websock.htm as wenn */
|
/* if the port is changed here, it needs to be changed in websock.htm as well */
|
||||||
"listening_ports", "80",
|
"listening_ports", "80",
|
||||||
|
|
||||||
NULL
|
NULL
|
||||||
|
Reference in New Issue
Block a user