The library with which to configure a Web Socket Server on a Mbed. This lib was coded by a day at least one year before when this description is written. It will be updated adopting mbed os 5.

Dependencies:   mbedTLSLibrary

Dependents:   SIMPLE_WSS

Revision:
1:73f2f67d1732
Parent:
0:86a479dd1814
--- a/WS_SERVER.cpp	Thu Dec 08 10:11:25 2016 +0000
+++ b/WS_SERVER.cpp	Sat Mar 03 18:47:34 2018 +0000
@@ -30,6 +30,15 @@
     printf("\r\n");
 #endif
 }
+template<typename T1, typename T2, typename T3>
+void DEBUG_PRINT_LINE(const char* arg_line, T1 arg_t1, T2 arg_t2, T3 arg_t3)
+{
+#ifdef DEBUG
+    printf("(WSS) ");
+    printf(arg_line, arg_t1, arg_t2, arg_t3);
+    printf("\r\n");
+#endif
+}
 }
 using namespace WS_SERVER;
 
@@ -38,7 +47,7 @@
     ,m_PortNumber(8085)
 {
     m_ListeningFlag = (false);
-    m_RxBuffer = new int8_t[1024];
+    m_RxBuffer = new uint8_t[1024];
     m_restAppDataLen = 0;
 
     m_DiscontiuanceFlag = false;
@@ -50,7 +59,7 @@
     ,m_PortNumber(arg_PortNumber)
 {
     m_ListeningFlag = (false);
-    m_RxBuffer = new int8_t[arg_RxBufferSize];
+    m_RxBuffer = new uint8_t[arg_RxBufferSize];
     m_restAppDataLen = 0;
 
     m_DiscontiuanceFlag = false;
@@ -127,8 +136,8 @@
         //  Main WSS Communication----------------------------------
         while(m_tcpcon.is_connected()) {
             DEBUG_PRINT_LINE("(WSS) Connected");
-            handshake();
-            while(!m_DiscontiuanceFlag)rxMessage();
+            if(handshake())
+                while(!m_DiscontiuanceFlag)rxMessage();
             DEBUG_PRINT_LINE("(WSS) Closing");
             // txClosing(1002, "RecievedNot Masked Data");
         }
@@ -198,13 +207,12 @@
     }
     DEBUG_PRINT_LINE("Data size: %d Bytes", strlen((char*) m_RxBuffer));
     for(int i = 0; i < strlen((char*) m_RxBuffer); i++)
-        DEBUG_PRINT_LINE("Data%5d: %x", i, m_RxBuffer[i]);
+        DEBUG_PRINT_LINE("Data%5d: %2x (%3d)", i, m_RxBuffer[i], m_RxBuffer[i]);
     //
     //  Data Parsing
     //
     l_MesuredDataLen++;
     m_FIN_RSV = m_RxBuffer[0] >> 4;
-    DEBUG_PRINT_LINE("FIN RSV: %x", m_FIN_RSV);
     //If FIN is 1, the data is the last of a sequence.
     if(m_FIN_RSV >> 3)
         m_EODFlag = true;
@@ -237,7 +245,8 @@
     if(m_Mask == 0) {
         m_DiscontiuanceFlag = true;
     }
-    m_PayloadLen = m_RxBuffer[1] & (uint64_t)0x7f;
+    DEBUG_PRINT_LINE("Mask   : %x", m_Opcode);
+    m_PayloadLen = (uint64_t)(m_RxBuffer[1] & 0x7f);
     if(m_PayloadLen < 0x07e) {
         l_MesuredDataLen += m_PayloadLen;
         //  Buffer [2] [3] [4] [5] have Masking_Key
@@ -245,6 +254,7 @@
         if(m_Mask) for(int i = 0; i < 4; i++) m_Masking_key[i] = (m_RxBuffer[2 + i]);
         //  The Head of Payload data is at buffer[6]
         m_PayloadData = m_RxBuffer + 6;
+        DEBUG_PRINT_LINE("PL Len : %x", (uint32_t)m_PayloadLen);
     } else if (m_PayloadLen == 0x07e) {
         l_MesuredDataLen += m_PayloadLen;
         //  Two succeeded bytes buffer [2] and [3] have SubPayload
@@ -255,6 +265,7 @@
         if(m_Mask) for(int i = 0; i < 4; i++) m_Masking_key[i] = (m_RxBuffer[4 + i]);
         //  The Head of Payload data is at buffer[8]
         m_PayloadData = m_RxBuffer + 8;
+        DEBUG_PRINT_LINE("PL Len : %x", (uint32_t)m_PayloadLen);
     } else if (m_PayloadLen == 0x07f) {
         l_MesuredDataLen += m_PayloadLen;
         //  Eight succeeded bytes buffer [2], [3], [4], [5], [6], [7], [8], and [9] have SubPayload
@@ -267,18 +278,17 @@
         if(m_Mask) for(int i = 0; i < 4; i++) m_Masking_key[i] = (m_RxBuffer[10 + i]);
         //  The Head of Payload data is at buffer[14]
         m_PayloadData = m_RxBuffer + 14;
+        DEBUG_PRINT_LINE("PL Len : %x%x", (uint32_t)(m_PayloadLen>>32),(uint32_t)(m_PayloadLen&0xffffffff));
     }
     DEBUG_PRINT_LINE("Data parsing ... 2/3");
-    DEBUG_PRINT_LINE("Mask   : %x", m_Opcode);
-    DEBUG_PRINT_LINE("PL Len : %x", m_PayloadLen);
-    
+
     //  Because there is no negotiation of Extention, Extention data is regarded as none.
     m_ExtensionLen = 0;
     m_ApplicationLen = m_PayloadLen - m_ExtensionLen;
     m_restAppDataLen = m_ApplicationLen;
     DEBUG_PRINT_LINE("Data parsing ... 3/3");
-    DEBUG_PRINT_LINE("Application Data Len: %d byte");
-    
+    DEBUG_PRINT_LINE("Application Data Len: %08x%08x Byte", (uint32_t)(m_ApplicationLen>>32),   (uint32_t)(m_ApplicationLen &0xffffffff));
+
     if(l_MesuredDataLen != l_RxDataLen) {
         m_DiscontiuanceFlag = true;
     }