Websocket client test with Vodafone USB Modems

Dependencies:   WebSocketClient VodafoneUSBModem mbed mbed-rtos

Fork of VodafoneK3770WebsocketTestBeta by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "VodafoneUSBModem.h"
00003 #include "Websocket.h"
00004 
00005 void test(void const*) 
00006 {
00007     VodafoneUSBModem modem;
00008     Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw");
00009     char recv[128];
00010     
00011     int ret = modem.connect("pp.vodafone.co.uk");
00012     if(ret)
00013     {
00014       printf("Could not connect\n");
00015       return;
00016     }
00017     
00018     bool c = ws.connect();
00019     printf("Connect result: %s\n", c?"OK":"Failed");
00020     
00021     for(int i = 0; i < 10000; i++)
00022     {
00023         if(!(i%100))
00024         {
00025           int ret = ws.send("WebSocket Hello World over the Vodafone Network!");
00026           if(ret<0)
00027           {
00028             printf("Timeout\n");
00029             ws.close();
00030             c = ws.connect();
00031             printf("Connect result: %s\n", c?"OK":"Failed");
00032           }
00033         }
00034         
00035         if (ws.read(recv)) {
00036             printf("rcv: %s\r\n", recv);
00037         }
00038 
00039     }
00040     
00041     modem.disconnect();  
00042 
00043     while(1) {
00044     }
00045 }
00046 
00047 
00048 int main()
00049 {
00050   Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
00051   DigitalOut led(LED1);
00052   while(1)
00053   {
00054     led=!led;
00055     Thread::wait(1000);  
00056   }
00057 
00058   return 0;
00059 }