NerfUS / HardwareInterface

Dependents:   NerfUS_cmake_add_library_from_mbed NerfUS NerfUSGameCoordinator

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WSRequest.cpp Source File

WSRequest.cpp

Go to the documentation of this file.
00001 /**
00002 @file WSRequest.cpp
00003 
00004 @brief Allow communication with a server using a specific websocket.
00005 
00006 @poject NerfUS, Team P5
00007 */
00008 #include "WSRequest.hpp"
00009 
00010 
00011 WSRequest::WSRequest(char *url) : ws(url)
00012 {
00013     eth.init(); //Use DHCP
00014     eth.connect();
00015     printf("IP Address is %s\n\r", eth.getIPAddress());
00016 
00017     ws.connect();
00018 }
00019 
00020 int WSRequest::send(char *buffer)
00021 {
00022     return ws.send(buffer);
00023 }
00024 
00025 bool WSRequest::onMessage(char *buffer)
00026 {
00027     while (!ws.read(buffer))
00028     {
00029         wait(0.1);
00030     }
00031     return true;
00032 }
00033 
00034 WSRequest::~WSRequest()
00035 {
00036     ws.close();
00037     eth.disconnect();
00038 }