From b52d0cfba053036348886bf9321a15116d32e139 Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Wed, 30 Sep 2015 12:15:06 +0800 Subject: [PATCH] Websocket demo --- user/user_main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/user/user_main.c b/user/user_main.c index f4c11f6..5985d50 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -25,6 +25,7 @@ some pictures of cats. #include "espfs.h" #include "captdns.h" #include "webpages-espfs.h" +#include "cgiwebsocket.h" //The example can print out the heap use every 3 seconds. You can use this to catch memory leaks. //#define SHOW_HEAP_USE @@ -46,6 +47,19 @@ int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pas return 0; } +void myWebsocketRecv(Websock *ws, char *data, int len, int flags) { + int i; + os_printf("Websocket: Received data: "); + for (i=0; irecvCb=myWebsocketRecv; + cgiWebsocketSend(ws, "Hi, Websocket!", 14, WEBSOCK_FLAG_NONE); +} + + #ifdef ESPFS_POS CgiUploadFlashDef uploadParams={ .type=CGIFLASH_TYPE_ESPFS, @@ -102,6 +116,8 @@ HttpdBuiltInUrl builtInUrls[]={ {"/wifi/connstatus.cgi", cgiWiFiConnStatus, NULL}, {"/wifi/setmode.cgi", cgiWiFiSetMode, NULL}, + {"/websocket/ws.cgi", cgiWebsocket, myWebsocketConnect}, + {"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem {NULL, NULL, NULL} };