Websocket Hello World over an ethernet network

Dependencies:   EthernetNetIf mbed DNSResolver

Committer:
samux
Date:
Tue Nov 15 19:40:28 2011 +0000
Revision:
6:aa2b63dc24f3
Parent:
5:f34f1ae8de92
Child:
7:ecad5b72fa16

        

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 //Here, we format the string we will be sending to the server
samux 6:aa2b63dc24f3 22 //the format we are sending in is JSON
samux 6:aa2b63dc24f3 23 ws.send("Hello World");
samux 6:aa2b63dc24f3 24 tmr.start();
samux 6:aa2b63dc24f3 25 }
samux 6:aa2b63dc24f3 26 Net::poll();
samux 6:aa2b63dc24f3 27 }
samux 6:aa2b63dc24f3 28 }
samux 0:dac316268a0c 29 }