test-applet-add-reset-button-and-colour-socket-status.patch
authorAndy Green <andy@warmcat.com>
Thu, 11 Nov 2010 13:19:19 +0000 (13:19 +0000)
committerAndy Green <andy@warmcat.com>
Thu, 11 Nov 2010 13:19:19 +0000 (13:19 +0000)
Signed-off-by: Andy Green <andy@warmcat.com>
lib/parsers.c
test-server/test-server.c
test-server/test.html

index 3436baf..9a767f8 100644 (file)
@@ -248,11 +248,12 @@ int libwebsocket_interpret_incoming_packet(struct libwebsocket *wsi,
 {
        int n;
 
+#ifdef DEBUG
        fprintf(stderr, "received %d byte packet\n", (int)len);
        for (n = 0; n < len; n++)
                fprintf(stderr, "%02X ", buf[n]);
        fprintf(stderr, "\n");
-
+#endif
        /* let the rx protocol state machine have as much as it needs */
        
        n = 0;
index 1ab6fd2..1bba6e0 100644 (file)
@@ -126,6 +126,8 @@ static int websocket_callback(struct libwebsocket * wsi,
         */
        case LWS_CALLBACK_RECEIVE:
                fprintf(stderr, "Received %d bytes payload\n", (int)len);
+               if (strcmp(in, "reset\n") == 0)
+                       pss->number = 0;
                break;
 
        /*
index 19c6218..1539209 100644 (file)
@@ -2,10 +2,23 @@
 <html lang="en">
 <head>
  <meta charset=utf-8 />
- <title>Minimal Websocket message sender</title>
+ <title>Minimal Websocket test app</title>
 </head>
 
 <body>
+<h2>libwebsockets "dumb-increment-protocol" test applet</h2>
+The incrementing number is coming from the server.
+Click the button to send the server a websocket message to
+reset the number.<br><br>
+
+<table>
+       <tr>
+               <td align=center><input type=button id=offset value="Reset counter" onclick="reset();" ></td>
+               <td width=100 align=center><div id=number> </div></td>
+               <td id=statustd align=center><div id=wsstatus>Not initialized</div></td>
+       </tr>
+</table>
+
 <script>
        var pos = 0;
        var websocket_ads;
        else
                websocket_ads = "ws://127.0.0.1:7681"
        
-    var socket = new WebSocket(websocket_ads, "dumb-increment-protocol");  
+       var socket = new WebSocket(websocket_ads, "dumb-increment-protocol");  
 
        try {
-//        alert('<p class="event">Socket Status: '+socket.readyState);  
-  
-        socket.onopen = function(){  
- //            alert('<p class="event">Socket Status: '+socket.readyState+' (open)');  
-        }  
-  
-        socket.onmessage = got_packet;
-  
-        socket.onclose = function(){  
-             alert('<p class="event">Socket Status:  (Closed)');  
-        }
-          } catch(exception){  
-             alert('<p>Error'+exception);  
-          }
-       
-function got_packet(msg){
+               socket.onopen = function() {
+                       statustd.style.backgroundColor = "#40ff40";
+                       wsstatus.textContent = " websocket connection opened ";
+               } 
+
+               socket.onmessage =function got_packet(msg) {
+                       number.textContent = msg.data + "\n";
+               } 
+
+               socket.onclose = function(){
+                       statustd.style.backgroundColor = "#ff4040";
+                       wsstatus.textContent = " websocket connection closed ";
+               }
+       } catch(exception) {
+               alert('<p>Error'+exception);  
+       }
+
+function reset() {
+       socket.send("reset\n");
+}
 
-//     alert('got packet' + msg.data);
-       document.body.textContent = msg.data + "\n";
-       
-}  
 </script>
 
 </body>