WebSocket client library

Revision:
25:2214f1e5d4a3
Parent:
24:15112fd8ad45
--- a/Websocket.cpp	Mon Mar 19 13:54:32 2012 +0000
+++ b/Websocket.cpp	Wed May 09 11:45:54 2012 +0000
@@ -139,34 +139,21 @@
             return false;
         }
 
-
         //open the connection
-        char recv[30];
-        string str;
         sprintf(cmd, "open %s %s\r\n", ip_domain.c_str(), port.c_str());
-        wifi->send(cmd, "NO", recv);
-        str = recv;
-
+        if (!wifi->send(cmd, "OPEN")) {
+            if (wifi->send(cmd, "nected")) {
 #ifdef DEBUG
-        printf("Websocket::connect recv: %s\r\n", recv);
+                printf("will try to close the conn\r\n");
 #endif
-
-        if (str.find("Connected") == string::npos && str.find("OPEN") == string::npos) {
-#ifdef DEBUG
-            printf("Websocket::connect cannot open\r\n");
-#endif
-            return false;
-        }
-
-        if (str.find("Connected") != string::npos) {
-#ifdef DEBUG
-            printf("will try to close the conn\r\n");
-#endif
-            if (!wifi->send("close\r\n", "CLOS")) {
+                if (!wifi->send("close\r", "CLOS")) {
+                    return false;
+                }
+                if (!wifi->send(cmd, "OPEN"))
+                    return false;
+            } else {
                 return false;
             }
-            if (!wifi->send(cmd, "OPEN"))
-                return false;
         }
 
         //send websocket HTTP header
@@ -314,7 +301,7 @@
     sendLength(strlen(str));
     sendMask();
     if (netif == WIF) {
-        wifi->send(str, "NO");
+        wifi->send(str, NULL);
     }
 #ifdef TARGET_LPC1768
     else if (netif == ETH) {
@@ -460,7 +447,7 @@
     sendLength(0);
     sendMask();
     if (netif == WIF) {
-        
+
         wait(0.25);
         if (!wifi->cmdMode()) {
 #ifdef DEBUG
@@ -470,7 +457,7 @@
         }
         wait(0.25);
 
-        wifi->send("close\r", "NO");
+        wifi->send("close\r", NULL);
 
         if (!wifi->exit())
             return false;
@@ -506,7 +493,7 @@
         }
         wait(0.25);
 
-        wifi->send("show c\r\n", "NO", str);
+        wifi->send("show c\r\n", NULL, str);
 #ifdef DEBUG
         printf("Websocket::connected: str: %s\r\n", str);
 #endif