Wrapper of the mbed hardware
Dependents: NerfUS_cmake_add_library_from_mbed NerfUS NerfUSGameCoordinator
Diff: source/WSRequest.cpp
- Revision:
- 5:0a7810520b9e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/WSRequest.cpp Wed Mar 01 03:53:01 2017 +0000 @@ -0,0 +1,38 @@ +/** +@file WSRequest.cpp + +@brief Allow communication with a server using a specific websocket. + +@poject NerfUS, Team P5 +*/ +#include "WSRequest.hpp" + + +WSRequest::WSRequest(char *url) : ws(url) +{ + eth.init(); //Use DHCP + eth.connect(); + printf("IP Address is %s\n\r", eth.getIPAddress()); + + ws.connect(); +} + +int WSRequest::send(char *buffer) +{ + return ws.send(buffer); +} + +bool WSRequest::onMessage(char *buffer) +{ + while (!ws.read(buffer)) + { + wait(0.1); + } + return true; +} + +WSRequest::~WSRequest() +{ + ws.close(); + eth.disconnect(); +} \ No newline at end of file