Simple websocket client based on the original with a few added features such as: - setBaud() - set the baud rate for the communication - Initialize() - mimics the constructor - chaged read() to readmsg() to avoid confusion with other functions

Dependents:   IoT_Ex BatteryModelTester BatteryModelTester

Fork of WebSocketClient by Samuel Mokrani

Revision:
25:4a98a3b83b87
Parent:
22:d2c00e47527c
Parent:
24:6f30d0c4ff7b
--- a/Websocket.cpp	Wed Aug 31 10:03:43 2016 +0000
+++ b/Websocket.cpp	Tue Oct 04 16:46:59 2016 +0000
@@ -254,7 +254,7 @@
 }
 
 
-bool Websocket::readmsg(char * message) {
+int Websocket::readmsg(char * message) {
     int i = 0;
     uint32_t len_msg;
     char opcode = 0;
@@ -268,19 +268,19 @@
     while (true) {
         if (tmr.read() > 3) {
             DBG("timeout ws\r\n");
-            return false;
+            return -1;
         }
         
         if(!socket.is_connected())
         {
             WARN("Connection was closed by server");
-            return false;
+            return -1;
         }
 
         socket.set_blocking(false, 1);
         if (socket.receive(&opcode, 1) != 1) {
             socket.set_blocking(false, 2000);
-            return false;
+            return 0;
         }
 
         socket.set_blocking(false, 2000);
@@ -307,7 +307,7 @@
     }
 
     if (len_msg == 0) {
-        return false;
+        return 0;
     }
     DBG("length: %d", len_msg);
     
@@ -322,7 +322,7 @@
     int nb = read(message, len_msg, len_msg);
     DBG("Done nb:%d = read(message:%s, len_msg:%d, len_msg:%d)", nb, message, len_msg, len_msg);
     if (nb != len_msg)
-        return false;
+        return 0;
 
     for (i = 0; i < len_msg; i++) {
         message[i] = message[i] ^ mask[i % 4];
@@ -330,7 +330,7 @@
 
     message[len_msg] = '\0';
     DBG("Websocket::read() returning true, message:%s", message);
-    return true;
+    return 1;
 }
 
 bool Websocket::close() {