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.
Dependencies: LSM9DS1_Library_cal Servo mbed-rtos mbed
Fork of Websocket_Ethernet_HelloWorld by
main.cpp@0:1b0dc7de9db7, 2012-08-10 (annotated)
- Committer:
- samux
- Date:
- Fri Aug 10 11:15:53 2012 +0000
- Revision:
- 0:1b0dc7de9db7
- Child:
- 1:1c1802ec42a2
hello world using the websocket client library (ethernet)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| samux | 0:1b0dc7de9db7 | 1 | #include "mbed.h" |
| samux | 0:1b0dc7de9db7 | 2 | #include "EthernetInterface.h" |
| samux | 0:1b0dc7de9db7 | 3 | #include "Websocket.h" |
| samux | 0:1b0dc7de9db7 | 4 | |
| samux | 0:1b0dc7de9db7 | 5 | |
| samux | 0:1b0dc7de9db7 | 6 | int main() { |
| samux | 0:1b0dc7de9db7 | 7 | char recv[30]; |
| samux | 0:1b0dc7de9db7 | 8 | |
| samux | 0:1b0dc7de9db7 | 9 | EthernetInterface eth; |
| samux | 0:1b0dc7de9db7 | 10 | eth.init(); //Use DHCP |
| samux | 0:1b0dc7de9db7 | 11 | eth.connect(); |
| samux | 0:1b0dc7de9db7 | 12 | printf("IP Address is %s\n\r", eth.getIPAddress()); |
| samux | 0:1b0dc7de9db7 | 13 | |
| samux | 0:1b0dc7de9db7 | 14 | Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); |
| samux | 0:1b0dc7de9db7 | 15 | ws.connect(); |
| samux | 0:1b0dc7de9db7 | 16 | |
| samux | 0:1b0dc7de9db7 | 17 | while (1) { |
| samux | 0:1b0dc7de9db7 | 18 | int res = ws.send("WebSocket Hello World!"); |
| samux | 0:1b0dc7de9db7 | 19 | |
| samux | 0:1b0dc7de9db7 | 20 | if (ws.read(recv)) { |
| samux | 0:1b0dc7de9db7 | 21 | printf("rcv: %s\r\n", recv); |
| samux | 0:1b0dc7de9db7 | 22 | } |
| samux | 0:1b0dc7de9db7 | 23 | |
| samux | 0:1b0dc7de9db7 | 24 | wait(0.1); |
| samux | 0:1b0dc7de9db7 | 25 | } |
| samux | 0:1b0dc7de9db7 | 26 | } |
