Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
HTTPWebSocketHandler.h
00001 #ifndef HTTP_WEB_SOCKET_HANDLER_H 00002 #define HTTP_WEB_SOCKET_HANDLER_H 00003 00004 #include "mbed.h" 00005 #include "HTTPServer.h" 00006 #include "TemperatureSensor.h" 00007 #include "RGBLed.h" 00008 00009 // Abstrct base class for state delegation 00010 class HTTPWebSocketState : public HTTPData { 00011 public: 00012 virtual HTTPStatus init(HTTPConnection *conn) = 0; 00013 virtual HTTPHandle data(HTTPConnection *conn, void *data, int len) = 0; 00014 virtual HTTPHandle send(HTTPConnection *conn, int maxData) = 0; 00015 }; 00016 00017 // State class for connecting the WebSocket, performing security handshake 00018 class HTTPWebSocketConnectingState : public HTTPWebSocketState { 00019 public: 00020 HTTPWebSocketConnectingState(); 00021 virtual HTTPStatus init(HTTPConnection *conn); 00022 virtual HTTPHandle data(HTTPConnection *conn, void *data, int len); 00023 virtual HTTPHandle send(HTTPConnection *conn, int maxData); 00024 private: 00025 // Helper functions 00026 uint32_t extractNumber(const char *keyValue); 00027 uint32_t countSpaces(const char *keyValue); 00028 uint32_t computeKeyPart(const char *keyValue); 00029 void hexStringToBinary(const char *hex, char *binary); 00030 00031 uint8_t challange[16]; 00032 }; 00033 00034 // State class for streaming the WebSocket 00035 class HTTPWebSocketStreamingState : public HTTPWebSocketState { 00036 public: 00037 HTTPWebSocketStreamingState(); 00038 virtual HTTPStatus init(HTTPConnection *conn); 00039 virtual HTTPHandle data(HTTPConnection *conn, void *data, int len); 00040 virtual HTTPHandle send(HTTPConnection *conn, int maxData); 00041 private: 00042 DigitalOut led; 00043 int sendCnt; 00044 }; 00045 00046 // HTTP handler for resorces that become WebSockets 00047 class HTTPWebSocketHandler : public HTTPHandler { 00048 public: 00049 HTTPWebSocketHandler(const char *path) : HTTPHandler(path) { 00050 printf("HTTPWebSocketHandler: %s\n", path); 00051 } 00052 00053 protected: 00054 virtual void reg(HTTPServer *); 00055 virtual HTTPStatus init(HTTPConnection *conn) const; 00056 virtual HTTPHandle data(HTTPConnection *conn, void *data, int len) const; 00057 virtual HTTPHandle send(HTTPConnection *, int) const; 00058 }; 00059 00060 #endif
Generated on Wed Jul 13 2022 23:42:33 by
1.7.2