Fork of https://os.mbed.com/teams/mbed_example/code/WebSocketClient/ Update to MbedOS6
Diff: Websocket.h
- Revision:
- 11:9ee267dafdd7
- Parent:
- 9:efa2c147bee1
--- a/Websocket.h Sat May 22 06:57:45 2021 +0000 +++ b/Websocket.h Mon May 24 19:37:04 2021 +0000 @@ -43,21 +43,23 @@ * * int main() { * EthernetInterface eth; - * eth.init(); //Use DHCP * eth.connect(); - * printf("IP Address is %s\n\r", eth.getIPAddress()); + * SocketAddress ip; + * eth.get_ip_address(&ip); + * const char *p_ip = ip.get_ip_address(); + * printf("IP address: %s\n", p_ip ? p_ip : "None"); * - * Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); + * Websocket ws("ws://echo.websocket.org/"); * ws.connect(); - * + * char recv[20]; * while (1) { - * int res = ws.send("WebSocket Hello World!"); - * + * int res = ws.send((char*)"WebSocket Hello World!"); + * printf("Error: %d\n", res); * if (ws.read(recv)) { * printf("rcv: %s\r\n", recv); * } * - * wait(0.1); + * thread_sleep_for(100ms); * } * } * @endcode @@ -70,8 +72,10 @@ * Constructor * * @param url The Websocket url in the form "ws://ip_domain[:port]/path" (by default: port = 80) + * @param iface The NetworkInterface + * @param ca TLS certificate (root_ca_cert) */ - Websocket(char * url, NetworkInterface * iface); + Websocket(char * url, NetworkInterface * iface, const char* ca = nullptr); /** * Connect to the websocket url @@ -124,11 +128,12 @@ uint16_t port; char host[32]; char path[64]; + bool secured; - TCPSocket socket; + Socket* _socket; int read(char * buf, int len, int min_len = -1); int write(char * buf, int len); }; -#endif +#endif \ No newline at end of file