sample program of Web socket server.

Dependencies:   mbed WS_SERVER EthernetInterface HTTP_SERVER

Revision:
0:6a6f021d1f40
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 21 19:34:01 2020 +0000
@@ -0,0 +1,78 @@
+#include "mbed.h"
+#include "WS_SERVER.h"
+#include "HTTP_SERVER.h"
+#include "rtos.h"
+#ifndef DEBUG
+//#define DEBUG
+#endif
+
+WSS wss(1024);
+HttpServer httpsvr;
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+Serial pc(USBTX, USBRX);
+
+void httpServerThread(void const* argument)
+{
+    if(httpsvr.init()) {
+        if(httpsvr.run() == 0)
+            printf("end\r\n");
+        else
+            printf("error end\r\n");
+    }
+}
+void test(void const* argument)
+{
+    while(true) { //wss.isListening()) {
+        led1 = !led1;
+        Thread::wait(500);
+    }
+}
+
+void websocketServerThread()//void const* argument)
+{
+    //
+    //  Websocket communication
+    //
+    //wss.txPing();
+    if(wss.init()) {
+        while(wss.isListening())wss.run();
+    }
+
+    //  -----Websocket com end-----
+    led3=led4=0;
+}
+
+void printRxData(void const* argument)
+{
+    char l_data;
+    wss.txPing();
+    while(1) {
+        if(wss.isReadable()) {
+            l_data = (char)wss.getRxData();
+            printf("(printRxData) %c(%d) \r\n", l_data, l_data);
+        }
+        else{
+            printf("no printings\r\n");
+            Thread::wait(500);
+        }
+    }
+}
+
+int main()
+{
+    //Thread httpListener(httpServerThread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25));
+    //httpServerThread();
+    Thread wssListener(websocketServerThread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25));
+    //Thread::wait(5000);
+    Thread printTaske(printRxData);
+    //websocketServerThread();
+    //wssListener.start(websocketServerThread);
+    //printTaske.start(printRxData);
+    //wssListener.terminate();
+    //printTaske.terminate();
+    return 0;
+}
+