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 (NetworkStack *ns, 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 66 of file Websocket.h.
Constructor & Destructor Documentation
| Websocket | ( | NetworkStack * | ns, |
| char * | url | ||
| ) |
Constructor.
- Parameters:
-
url The Websocket url in the form "ws://ip_domain[:port]/path" (by default: port = 80)
Definition at line 20 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 320 of file Websocket.cpp.
| bool connect | ( | ) |
Connect to the websocket url.
- Returns:
- true if the connection is established, false otherwise
Definition at line 121 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 332 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 241 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 229 of file Websocket.cpp.
Generated on Sun Jul 17 2022 09:02:19 by
1.7.2
