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.
11 #include "WebSockCallbacks.h"
16 struct mg_context
*ctx
= 0;
17 struct mg_callbacks callback_funcs
= {0};
18 tWebSockContext ws_ctx
;
21 const char *server_options
[] = {
22 /* document_root: The path to the test function websock.htm */
24 "../../examples/websocket",
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 */
35 callback_funcs
.init_context
= websock_init_lib
;
36 callback_funcs
.exit_context
= websock_exit_lib
;
38 ctx
= mg_start(&callback_funcs
, &ws_ctx
, server_options
);
40 mg_set_websocket_handler(ctx
,
43 websocket_ready_handler
,
44 websocket_data_handler
,
45 connection_close_handler
,
48 printf("Connect to localhost:%s/websock.htm\n",
49 mg_get_option(ctx
, "listening_ports"));
51 puts("Enter an (ASCII) character or * to exit:");
53 fgets(inbuf
, sizeof(inbuf
), stdin
);
55 if (inbuf
[0] == '*') {
58 inbuf
[0] = toupper(inbuf
[0]);
59 websock_send_broadcast(ctx
, inbuf
, 1);