From 5a28d517c61f1500b6c38876afd1c057819cc6a2 Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Thu, 21 Jan 2016 16:37:53 +0800 Subject: [PATCH] Add websocket echo cgi for Autobahn testing --- user/user_main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/user/user_main.c b/user/user_main.c index ad5da04..862b800 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -74,6 +74,18 @@ void myWebsocketConnect(Websock *ws) { cgiWebsocketSend(ws, "Hi, Websocket!", 14, WEBSOCK_FLAG_NONE); } +//On reception of a message, echo it back verbatim +void myEchoWebsocketRecv(Websock *ws, char *data, int len, int flags) { + os_printf("EchoWs: echo, len=%d\n", len); + cgiWebsocketSend(ws, data, len, flags); +} + +//Echo websocket connected. Install reception handler. +void myEchoWebsocketConnect(Websock *ws) { + os_printf("EchoWs: connect\n"); + ws->recvCb=myEchoWebsocketRecv; +} + #ifdef ESPFS_POS CgiUploadFlashDef uploadParams={ @@ -132,6 +144,7 @@ HttpdBuiltInUrl builtInUrls[]={ {"/wifi/setmode.cgi", cgiWiFiSetMode, NULL}, {"/websocket/ws.cgi", cgiWebsocket, myWebsocketConnect}, + {"/websocket/echo.cgi", cgiWebsocket, myEchoWebsocketConnect}, {"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem {NULL, NULL, NULL}