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 const *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.   | |
Static Public Member Functions | |
| static void | Websocket_Thread (void const *arg) | 
| Thread to start Websocket.   | |
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 72 of file Websocket.h.
Constructor & Destructor Documentation
| Websocket | ( | char const * | url ) | 
Constructor.
- Parameters:
 - 
  
url The Websocket url in the form "ws://ip_domain[:port]/path" (by default: port = 80)  
Definition at line 171 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 457 of file Websocket.cpp.
| bool connect | ( | ) | 
Connect to the websocket url.
- Returns:
 - true if the connection is established, false otherwise
 
Definition at line 273 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 469 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 381 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 369 of file Websocket.cpp.
| void Websocket_Thread | ( | void const * | arg ) |  [static] | 
        
Thread to start Websocket.
Definition at line 28 of file Websocket.cpp.
Generated on Fri Jul 22 2022 00:51:42 by
 1.7.2 
    