Example program with HTTPServer and sensor data streaming over TCPSockets, using Donatien Garnier's Net APIs and services code on top of LWIP. Files StreamServer.h and .cpp encapsulate streaming over TCPSockets. Broadcast is done by sendToAll(), and all incoming data is echoed back to the client. Echo code can be replaced with some remote control of the streaming interface. See main() that shows how to periodically send some data to all subscribed clients. To subscribe, a client should open a socket at <mbed_ip> port 123. I used few lines in TCL code to set up a quick sink for the data. HTTP files are served on port 80 concurrently to the streaming.

Dependencies:   mbed

Revision:
1:3ee499525aa5
Parent:
0:e614f7875b60
--- a/services/http/server/HTTPRequestDispatcher.cpp	Sat Jun 12 06:01:50 2010 +0000
+++ b/services/http/server/HTTPRequestDispatcher.cpp	Mon Jun 14 03:24:33 2010 +0000
@@ -46,7 +46,7 @@
   string meth;
   HTTP_METH methCode;
   
-  DBG("\r\nDispatching req\r\n");
+  DBG("Dispatching req\r\n");
   
   if( !getRequest(&rootPath, &fullPath, &meth ) )
   {
@@ -72,7 +72,7 @@
     return;
   }
   
-  DBG("\r\nLooking for a handler\r\n");
+  DBG("Looking for a handler\r\n");
   
   map< string, HTTPRequestHandler*(*)(const char*, const char*, TCPSocket*) >::iterator it;
   it = m_pSvr->m_lpHandlers.find(rootPath); //We are friends so we can do that
@@ -86,7 +86,7 @@
     return;
   }
   
-  DBG("\r\nHandler found.\r\n");
+  DBG("Handler found.\r\n");
   
   HTTPRequestHandler* pHdlr = (*it).second(rootPath.c_str(), fullPath.c_str(), m_pTCPSocket);
   m_pTCPSocket = NULL; //We don't own it anymore
@@ -104,7 +104,7 @@
     break;
   }
   
-  DBG("\r\nReq handled (or being handled)\r\n");
+  DBG("Req handled (or being handled)\r\n");
   close();
 }
 
@@ -162,7 +162,7 @@
   }
   *p = 0;
   
-  DBG("\r\nParsing request : %s\r\n", req);
+  DBG("Parsing request : %s\r\n", req);
   
   ret = sscanf(req, "%s %s HTTP/%*d.%*d", c_meth, c_path);
   if(ret !=2)
@@ -180,7 +180,7 @@
        
   *rootPath = string(c_path);
   
-  DBG("\r\nParse OK :\r\nRoot Path : %s\r\nFull Path : %s\r\nMethod Path : %s\r\n", rootPath->c_str(), fullPath->c_str(), meth->c_str());
+  DBG("Parse OK :\r\nRoot Path : %s\r\nFull Path : %s\r\nMethod Path : %s\r\n", rootPath->c_str(), fullPath->c_str(), meth->c_str());
   
   return true;
 
@@ -190,11 +190,11 @@
 void HTTPRequestDispatcher::onTCPSocketEvent(TCPSocketEvent e)
 {
 
-  DBG("\r\nEvent %d\r\n", e);
+  DBG("Event %d\r\n", e);
   
   if(m_closed)
   {
-    DBG("\r\nWARN: Discarded\r\n");
+    DBG("WARN: Discarded\r\n");
     return;
   }