OK connect Eth View: http://sockets.mbed.org/demo/viewer
Dependencies: EthernetInterface WebSocketClient mbed-rtos mbed
Fork of Websocket_Ethernet_HelloWorld by
main.cpp@3:9dd9b7afa272, 2014-04-27 (annotated)
- Committer:
- avnisha
- Date:
- Sun Apr 27 06:58:33 2014 +0000
- Revision:
- 3:9dd9b7afa272
- Parent:
- 1:1c1802ec42a2
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 1:1c1802ec42a2 | 1 | #include "mbed.h" |
samux | 1:1c1802ec42a2 | 2 | #include "EthernetInterface.h" |
samux | 1:1c1802ec42a2 | 3 | #include "Websocket.h" |
samux | 1:1c1802ec42a2 | 4 | |
samux | 1:1c1802ec42a2 | 5 | |
samux | 1:1c1802ec42a2 | 6 | int main() { |
avnisha | 3:9dd9b7afa272 | 7 | char recv[30]; |
avnisha | 3:9dd9b7afa272 | 8 | int ret; |
samux | 1:1c1802ec42a2 | 9 | |
samux | 1:1c1802ec42a2 | 10 | EthernetInterface eth; |
samux | 1:1c1802ec42a2 | 11 | eth.init(); //Use DHCP |
samux | 1:1c1802ec42a2 | 12 | eth.connect(); |
samux | 1:1c1802ec42a2 | 13 | printf("IP Address is %s\n\r", eth.getIPAddress()); |
samux | 1:1c1802ec42a2 | 14 | |
avnisha | 3:9dd9b7afa272 | 15 | Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw"); |
samux | 1:1c1802ec42a2 | 16 | ws.connect(); |
samux | 1:1c1802ec42a2 | 17 | |
samux | 1:1c1802ec42a2 | 18 | while (1) { |
avnisha | 3:9dd9b7afa272 | 19 | ret = ws.send("WebSocket Hello World over Ethernet"); |
avnisha | 3:9dd9b7afa272 | 20 | printf("ret = %d\n", ret); |
avnisha | 3:9dd9b7afa272 | 21 | if (ws.read(recv)) |
avnisha | 3:9dd9b7afa272 | 22 | printf("recv: %s\r\n", recv); |
samux | 1:1c1802ec42a2 | 23 | wait(1.0); |
samux | 1:1c1802ec42a2 | 24 | } |
samux | 1:1c1802ec42a2 | 25 | } |