zabuton library
Dependencies: CushionSock EthernetNetIf MbedJSONValue mbed
Websocket Class Reference
Websocket client Class. More...
#include <Websocket.h>
Public Member Functions | |
Websocket (char *url, Wifly *wifi) | |
Constructor. | |
Websocket (char *url, EthernetNetIf *e) | |
Constructor for an ethernet communication. | |
bool | connect () |
Connect to the websocket url. | |
void | send (char *str) |
Send a string according to the websocket format: 00 str ff. | |
bool | read (char *message) |
Read a websocket message. | |
bool | connected () |
To see if there is a websocket connection active. | |
bool | close () |
Close the websocket connection. | |
std::string | getPath () |
Accessor: get path from the websocket url. |
Detailed Description
Websocket client Class.
Warning: you must use a wifi module (Wifly RN131-C) or an ethernet network to use this class
Example (wifi network):
#include "mbed.h" #include "Wifly.h" #include "Websocket.h" Serial pc(USBTX, USBRX); Wifly * wifly; Websocket * ws; int main() { wifly = new Wifly(p9, p10, p20, "network", "password", true); ws = new Websocket("ws://ip_domain/path", wifly); if(wifly->join()) { if(ws->connect()) { pc.printf("ws connected\r\n"); while(1) { wait(0.1); ws->send("test"); } } else pc.printf("ws not connected\r\n"); } else pc.printf("join network failed\r\n"); }
Example (ethernet network):
#include "mbed.h" #include "Websocket.h" Serial pc(USBTX, USBRX); Websocket * ws; int main() { ws = new Websocket("ws://ip_domain/path"); if(ws->connect()) { pc.printf("ws connected\r\n"); while(1) { wait(0.1); ws->send("test"); } } else pc.printf("ws not connected\r\n"); }
Definition at line 118 of file Websocket.h.
Constructor & Destructor Documentation
Websocket | ( | char * | url, |
Wifly * | wifi | ||
) |
Constructor.
- Parameters:
-
url The Websocket url in the form "ws://ip_domain[:port]/path" (by default: port = 80) wifi pointer to a wifi module (the communication will be establish by this module)
Definition at line 8 of file Websocket.cpp.
Websocket | ( | char * | url, |
EthernetNetIf * | e | ||
) |
Constructor for an ethernet communication.
- Parameters:
-
url The Websocket url in the form "ws://ip_domain[:port]/path" (by default: port = 80)
Definition at line 23 of file Websocket.cpp.
Member Function Documentation
bool close | ( | ) |
Close the websocket connection.
- Returns:
- true if the connection has been closed, false otherwise
Definition at line 352 of file Websocket.cpp.
bool connect | ( | ) |
Connect to the websocket url.
- Returns:
- true if the connection is established, false otherwise
Definition at line 149 of file Websocket.cpp.
bool connected | ( | ) |
To see if there is a websocket connection active.
- Returns:
- true if there is a connection active
Definition at line 380 of file Websocket.cpp.
std::string getPath | ( | ) |
Accessor: get path from the websocket url.
- Returns:
- path
Definition at line 421 of file Websocket.cpp.
bool read | ( | char * | message ) |
Read a websocket message.
- Parameters:
-
message pointer to the string to be read (null if drop frame)
- Returns:
- true if a string has been read, false otherwise
Definition at line 303 of file Websocket.cpp.
void send | ( | char * | str ) |
Send a string according to the websocket format: 00 str ff.
- Parameters:
-
str string to be sent
Definition at line 285 of file Websocket.cpp.
Generated on Thu Jul 14 2022 08:11:09 by 1.7.2