]> git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/examples/websocket/websocket.c
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / civetweb / examples / websocket / websocket.c
1 /* This example uses deprecated interfaces: global websocket callbacks.
2 They have been superseeded by URI specific callbacks.
3 See examples/embedded_c for an up to date example.
4 */
5
6 #include <stdio.h>
7 #include <ctype.h>
8 #include <string.h>
9
10 #include "civetweb.h"
11 #include "WebSockCallbacks.h"
12
13 int
14 main(void)
15 {
16 struct mg_context *ctx = 0;
17 struct mg_callbacks callback_funcs = {0};
18 tWebSockContext ws_ctx;
19 char inbuf[4];
20
21 const char *server_options[] = {
22 /* document_root: The path to the test function websock.htm */
23 "document_root",
24 "../../examples/websocket",
25
26 /* port: use http standard to match websocket url in websock.htm:
27 ws://127.0.0.1/MyWebSock */
28 /* if the port is changed here, it needs to be changed in
29 websock.htm as well */
30 "listening_ports",
31 "80",
32
33 NULL};
34
35 callback_funcs.init_context = websock_init_lib;
36 callback_funcs.exit_context = websock_exit_lib;
37
38 ctx = mg_start(&callback_funcs, &ws_ctx, server_options);
39
40 mg_set_websocket_handler(ctx,
41 "/MyWebSock",
42 NULL,
43 websocket_ready_handler,
44 websocket_data_handler,
45 connection_close_handler,
46 NULL);
47
48 printf("Connect to localhost:%s/websock.htm\n",
49 mg_get_option(ctx, "listening_ports"));
50
51 puts("Enter an (ASCII) character or * to exit:");
52 for (;;) {
53 fgets(inbuf, sizeof(inbuf), stdin);
54
55 if (inbuf[0] == '*') {
56 break;
57 }
58 inbuf[0] = toupper(inbuf[0]);
59 websock_send_broadcast(ctx, inbuf, 1);
60 }
61
62 mg_stop(ctx);
63
64 return 0;
65 }