sample program of Web socket server.

Dependencies:   mbed WS_SERVER EthernetInterface HTTP_SERVER

Files at this revision

API Documentation at this revision

Comitter:
aktk
Date:
Wed Oct 21 19:34:01 2020 +0000
Commit message:
I verified it worked in 2016. but some libraries seemed modified which I have forgot, so idk if it works now.

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
HTTP_SERVER.lib Show annotated file Show diff for this revision Revisions of this file
WS_SERVER.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Wed Oct 21 19:34:01 2020 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/EthernetInterface/#183490eb1b4a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTP_SERVER.lib	Wed Oct 21 19:34:01 2020 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/aktk/code/HTTP_SERVER/#0ee7d100db24
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WS_SERVER.lib	Wed Oct 21 19:34:01 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/aktk/code/WS_SERVER/#ccaae77f91b8
--- /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;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 21 19:34:01 2020 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf
\ No newline at end of file