Hello World program demonstrating HTML5 Websockets connecting via Ethernet
Dependencies: WebSocketClient
Fork of Websocket_Ethernet_HelloWorld by
main.cpp
00001 /* Copyright C2014 ARM, MIT License 00002 * 00003 * Author: Doug Anson (doug.anson@arm.com) 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00006 * and associated documentation files the "Software", to deal in the Software without restriction, 00007 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00008 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in all copies or 00012 * substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00015 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00016 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00017 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00018 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00019 */ 00020 00021 #include "mbed.h" 00022 #include "EthernetInterface.h" 00023 #include "Websocket.h" 00024 00025 // Blinky 00026 DigitalOut led(LED1); 00027 00028 int main() { 00029 00030 // announce 00031 printf("Websocket Example v1.0.0\r\n"); 00032 00033 // Create a network interface and connect 00034 EthernetInterface eth; 00035 eth.connect(); 00036 printf("IP Address is %s\n\r", eth.get_ip_address()); 00037 00038 // Create a websocket instance 00039 Websocket ws("ws://example.com:8080/", ð); 00040 int connect_error = ws.connect(); 00041 00042 // begin main loop 00043 while (true) { 00044 00045 // blink... 00046 led = !led; 00047 wait(0.5); 00048 00049 int error_c = ws.send("Hello World\r\n"); 00050 } 00051 }
Generated on Sat Jul 16 2022 20:33:51 by 1.7.2