Update examples to NOT use mg_*mprintf

This commit is contained in:
cpq committed 2022-08-13 20:09:51 +01:00
1 parent f122bd5797
commit 189aa80743
3 files changed
+11 -17

No files matched your search

+3 -5
View File
@@ -56,14 +56,12 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
static void timer_fn(void *arg) {
struct mg_mgr *mgr = (struct mg_mgr *) arg;
char *msg = mg_mprintf("{%Q:%Q,%Q:[%d,%d,%d]}", "method", "notification1",
"params", 1, 2, 3);
// Broadcast message to all connected websocket clients.
for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) {
// Send JSON-RPC notifications to marked connections
if (c->label[0] == 'W') mg_ws_send(c, msg, strlen(msg), WEBSOCKET_OP_TEXT);
if (c->label[0] != 'W') continue;
mg_ws_printf(c, WEBSOCKET_OP_TEXT, "{%Q:%Q,%Q:[%d,%d,%d]}", "method",
"notification1", "params", 1, 2, 3);
}
free(msg);
}
int main(void) {