Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 Wed Jul 13 2022 23:37:28 by
1.7.2
