Websocket communication

Dependents:   Ethernet

Files at this revision

API Documentation at this revision

Comitter:
13075593
Date:
Sun Apr 03 15:44:52 2016 +0000
Commit message:
Websocket communication

Changed in this revision

WebSocket_COMM.cpp Show annotated file Show diff for this revision Revisions of this file
WebSocket_COMM.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebSocket_COMM.cpp	Sun Apr 03 15:44:52 2016 +0000
@@ -0,0 +1,27 @@
+#include "WebSocket_COMM.h"
+
+WebSocket_Communication::WebSocket_Communication(string _url)
+{
+    url = new char[_url.length()+1];
+    strcpy(url, _url.c_str());
+    
+    printf("URL : %s \n",url);
+    webSocket = new Websocket(url);
+}
+
+void WebSocket_Communication::initWebSocket()
+{
+    
+    int nbTry = 0;
+    while(!webSocket->connect() && nbTry <3)
+    {
+        printf("Connot connect Websocket, retrying \n");
+        ++nbTry;
+        wait(0.75);
+    }
+}
+
+void WebSocket_Communication::sendDataWebSocket(char *data)
+{
+    webSocket->send(data);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebSocket_COMM.h	Sun Apr 03 15:44:52 2016 +0000
@@ -0,0 +1,19 @@
+#ifndef WS_COMM_H
+#define WS_COMM_H
+
+#include "Websocket.h"
+#include <string>
+
+class WebSocket_Communication
+{
+    public:
+        WebSocket_Communication(string url);
+        void initWebSocket();
+        void sendDataWebSocket(char *data);
+        
+    private : 
+        Websocket *webSocket;
+        char *url;
+};
+
+#endif
\ No newline at end of file