Simple websocket client

Dependents:   Websocket_Ethernet_HelloWorld Websocket_Wifly_HelloWorld RPC_Wifly_HelloWorld RPC_Ethernet_HelloWorld ... more

Revision:
5:bb09d7a6c92f
Parent:
4:466f90b7849a
Child:
6:86e89a0369b9
--- a/Websocket.cpp	Mon Aug 20 08:50:51 2012 +0000
+++ b/Websocket.cpp	Wed Aug 29 13:49:48 2012 +0000
@@ -184,6 +184,12 @@
             DBG("timeout ws\r\n");
             return false;
         }
+        
+        if(!socket.is_connected())
+        {
+            WARN("Connection was closed by server");
+            return false;
+        }
 
         socket.set_blocking(false, 1);
         if (socket.receive(&opcode, 1) != 1) {
@@ -262,6 +268,12 @@
     int res = 0, idx = 0;
     
     for (int j = 0; j < MAX_TRY_WRITE; j++) {
+    
+        if(!socket.is_connected())
+        {
+            WARN("Connection was closed by server");
+            break;
+        }
 
         if ((res = socket.send_all(str + idx, len - idx)) == -1)
             continue;