Websocket Hello World over an ethernet network

Dependencies:   EthernetNetIf mbed DNSResolver

Committer:
samux
Date:
Tue Nov 15 20:26:38 2011 +0000
Revision:
7:ecad5b72fa16
Parent:
6:aa2b63dc24f3
Child:
8:66a7e251b8c5

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 6:aa2b63dc24f3 1 #include "mbed.h"
samux 6:aa2b63dc24f3 2 #include "Websocket.h"
samux 6:aa2b63dc24f3 3
samux 6:aa2b63dc24f3 4 Serial pc(USBTX, USBRX);
samux 6:aa2b63dc24f3 5 Timer tmr;
samux 6:aa2b63dc24f3 6
samux 6:aa2b63dc24f3 7 //Here, we create a Websocket instance in 'rw' (write) mode
samux 6:aa2b63dc24f3 8 //on the 'test' channel
samux 6:aa2b63dc24f3 9 Websocket ws("ws://sockets.mbed.org/ws/test/rw");
samux 6:aa2b63dc24f3 10
samux 6:aa2b63dc24f3 11 int main() {
samux 6:aa2b63dc24f3 12 while (1) {
samux 6:aa2b63dc24f3 13
samux 6:aa2b63dc24f3 14 while(!ws.connect())
samux 6:aa2b63dc24f3 15 pc.printf("cannot connect websocket, retrying\r\n");
samux 6:aa2b63dc24f3 16
samux 6:aa2b63dc24f3 17 tmr.start();
samux 6:aa2b63dc24f3 18 while (1) {
samux 6:aa2b63dc24f3 19 if(tmr.read() > 1)
samux 6:aa2b63dc24f3 20 {
samux 6:aa2b63dc24f3 21 ws.send("Hello World");
samux 6:aa2b63dc24f3 22 tmr.start();
samux 6:aa2b63dc24f3 23 }
samux 6:aa2b63dc24f3 24 Net::poll();
samux 6:aa2b63dc24f3 25 }
samux 6:aa2b63dc24f3 26 }
samux 0:dac316268a0c 27 }