Websocket communication
WebSocket_COMM.cpp@0:c10e8dc4cffd, 2016-04-03 (annotated)
- Committer:
- 13075593
- Date:
- Sun Apr 03 15:44:52 2016 +0000
- Revision:
- 0:c10e8dc4cffd
Websocket communication
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
13075593 | 0:c10e8dc4cffd | 1 | #include "WebSocket_COMM.h" |
13075593 | 0:c10e8dc4cffd | 2 | |
13075593 | 0:c10e8dc4cffd | 3 | WebSocket_Communication::WebSocket_Communication(string _url) |
13075593 | 0:c10e8dc4cffd | 4 | { |
13075593 | 0:c10e8dc4cffd | 5 | url = new char[_url.length()+1]; |
13075593 | 0:c10e8dc4cffd | 6 | strcpy(url, _url.c_str()); |
13075593 | 0:c10e8dc4cffd | 7 | |
13075593 | 0:c10e8dc4cffd | 8 | printf("URL : %s \n",url); |
13075593 | 0:c10e8dc4cffd | 9 | webSocket = new Websocket(url); |
13075593 | 0:c10e8dc4cffd | 10 | } |
13075593 | 0:c10e8dc4cffd | 11 | |
13075593 | 0:c10e8dc4cffd | 12 | void WebSocket_Communication::initWebSocket() |
13075593 | 0:c10e8dc4cffd | 13 | { |
13075593 | 0:c10e8dc4cffd | 14 | |
13075593 | 0:c10e8dc4cffd | 15 | int nbTry = 0; |
13075593 | 0:c10e8dc4cffd | 16 | while(!webSocket->connect() && nbTry <3) |
13075593 | 0:c10e8dc4cffd | 17 | { |
13075593 | 0:c10e8dc4cffd | 18 | printf("Connot connect Websocket, retrying \n"); |
13075593 | 0:c10e8dc4cffd | 19 | ++nbTry; |
13075593 | 0:c10e8dc4cffd | 20 | wait(0.75); |
13075593 | 0:c10e8dc4cffd | 21 | } |
13075593 | 0:c10e8dc4cffd | 22 | } |
13075593 | 0:c10e8dc4cffd | 23 | |
13075593 | 0:c10e8dc4cffd | 24 | void WebSocket_Communication::sendDataWebSocket(char *data) |
13075593 | 0:c10e8dc4cffd | 25 | { |
13075593 | 0:c10e8dc4cffd | 26 | webSocket->send(data); |
13075593 | 0:c10e8dc4cffd | 27 | } |