Simple websocket client
Fork of WebSocketClient by
Websocket Class Reference
Websocket client Class. More...
#include <Websocket.h>
Public Member Functions | |
Websocket (char *url) | |
Constructor. | |
bool | connect () |
Connect to the websocket url. | |
int | send (char *str) |
Send a string according to the websocket format (see rfc 6455) | |
bool | read (char *message) |
Read a websocket message. | |
bool | is_connected () |
To see if there is a websocket connection active. | |
bool | close () |
Close the websocket connection. |
Detailed Description
Websocket client Class.
Example (ethernet network):
#include "mbed.h" #include "EthernetInterface.h" #include "Websocket.h" int main() { EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); printf("IP Address is %s\n\r", eth.getIPAddress()); Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); ws.connect(); while (1) { int res = ws.send("WebSocket Hello World!"); if (ws.read(recv)) { printf("rcv: %s\r\n", recv); } wait(0.1); } }
Definition at line 68 of file Websocket.h.
Constructor & Destructor Documentation
Websocket | ( | char * | url ) |
Constructor.
- Parameters:
-
url The Websocket url in the form "ws://ip_domain[:port]/path" (by default: port = 80)
Definition at line 19 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 303 of file Websocket.cpp.
bool connect | ( | ) |
Connect to the websocket url.
- Returns:
- true if the connection is established, false otherwise
Definition at line 117 of file Websocket.cpp.
bool is_connected | ( | ) |
To see if there is a websocket connection active.
- Returns:
- true if there is a connection active
Definition at line 315 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 websocket frame has been read
Definition at line 226 of file Websocket.cpp.
int send | ( | char * | str ) |
Send a string according to the websocket format (see rfc 6455)
- Parameters:
-
str string to be sent
- Returns:
- the number of bytes sent
Definition at line 214 of file Websocket.cpp.
Generated on Tue Jul 19 2022 19:57:52 by 1.7.2