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

Committer:
iva2k
Date:
Mon Jun 14 03:24:33 2010 +0000
Revision:
1:3ee499525aa5
Parent:
0:e614f7875b60

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iva2k 0:e614f7875b60 1
iva2k 0:e614f7875b60 2 /*
iva2k 0:e614f7875b60 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
iva2k 0:e614f7875b60 4
iva2k 0:e614f7875b60 5 Permission is hereby granted, free of charge, to any person obtaining a copy
iva2k 0:e614f7875b60 6 of this software and associated documentation files (the "Software"), to deal
iva2k 0:e614f7875b60 7 in the Software without restriction, including without limitation the rights
iva2k 0:e614f7875b60 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
iva2k 0:e614f7875b60 9 copies of the Software, and to permit persons to whom the Software is
iva2k 0:e614f7875b60 10 furnished to do so, subject to the following conditions:
iva2k 0:e614f7875b60 11
iva2k 0:e614f7875b60 12 The above copyright notice and this permission notice shall be included in
iva2k 0:e614f7875b60 13 all copies or substantial portions of the Software.
iva2k 0:e614f7875b60 14
iva2k 0:e614f7875b60 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
iva2k 0:e614f7875b60 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
iva2k 0:e614f7875b60 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
iva2k 0:e614f7875b60 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
iva2k 0:e614f7875b60 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
iva2k 0:e614f7875b60 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
iva2k 0:e614f7875b60 21 THE SOFTWARE.
iva2k 0:e614f7875b60 22 */
iva2k 0:e614f7875b60 23
iva2k 0:e614f7875b60 24 //#ifdef DBG_H
iva2k 0:e614f7875b60 25 //#define DBG_H
iva2k 0:e614f7875b60 26
iva2k 0:e614f7875b60 27 #ifdef __LWIP_DEBUG
iva2k 0:e614f7875b60 28 #define __DEBUG
iva2k 0:e614f7875b60 29 #endif
iva2k 0:e614f7875b60 30
iva2k 0:e614f7875b60 31 #ifdef __DEBUG
iva2k 0:e614f7875b60 32
iva2k 0:e614f7875b60 33 #ifndef __DEBUGSTREAM
iva2k 0:e614f7875b60 34 #define __DEBUGSTREAM
iva2k 0:e614f7875b60 35
iva2k 0:e614f7875b60 36
iva2k 0:e614f7875b60 37 class DebugStream
iva2k 0:e614f7875b60 38 {
iva2k 0:e614f7875b60 39 public:
iva2k 0:e614f7875b60 40 static void debug(const char* format, ...);
iva2k 0:e614f7875b60 41 static void release();
iva2k 0:e614f7875b60 42 private:
iva2k 0:e614f7875b60 43
iva2k 0:e614f7875b60 44 };
iva2k 0:e614f7875b60 45
iva2k 0:e614f7875b60 46 #undef DBG
iva2k 0:e614f7875b60 47 #undef DBG_END
iva2k 0:e614f7875b60 48 #define DBG DebugStream::debug
iva2k 0:e614f7875b60 49 #define DBG_END DebugStream::release
iva2k 0:e614f7875b60 50
iva2k 1:3ee499525aa5 51 // more informative debug messages.
iva2k 1:3ee499525aa5 52 #if 1
iva2k 1:3ee499525aa5 53 #define WHEREFMT "[%s : %d : %s()] "
iva2k 1:3ee499525aa5 54 #define WHEREARG __FILE__, __LINE__, __FUNCTION__
iva2k 1:3ee499525aa5 55 // __FILE__ starts with a long pathname, we're interested in the tail
iva2k 1:3ee499525aa5 56 #define WHERECHOP 64 // How many chars to chop in the WHEREFMT
iva2k 1:3ee499525aa5 57 #define WHERESKIP 1 // What position to start in WHEREFMT
iva2k 0:e614f7875b60 58 #else
iva2k 1:3ee499525aa5 59 #define WHEREFMT "[%s : %d] "
iva2k 1:3ee499525aa5 60 #define WHEREARG __FILE__, __LINE__
iva2k 1:3ee499525aa5 61 // __FILE__ starts with a long pathname, we're interested in the tail
iva2k 1:3ee499525aa5 62 #define WHERECHOP 64 // How many chars to chop in the WHEREFMT
iva2k 1:3ee499525aa5 63 #define WHERESKIP 1 // What position to start in WHEREFMT
iva2k 1:3ee499525aa5 64 #endif
iva2k 1:3ee499525aa5 65 #undef DBG
iva2k 1:3ee499525aa5 66 #define DBG(_fmt, args...) DebugStream::debug(WHEREFMT _fmt, WHEREARG, ##args)
iva2k 1:3ee499525aa5 67 #undef DBGFIXLF
iva2k 1:3ee499525aa5 68 #define DBGFIXLF(_fmt, args...) DebugStream::debug(WHEREFMT _fmt, WHEREARG, ##args)
iva2k 1:3ee499525aa5 69
iva2k 1:3ee499525aa5 70 #endif // __DEBUGSTREAM
iva2k 1:3ee499525aa5 71
iva2k 1:3ee499525aa5 72 #else // __DEBUG
iva2k 0:e614f7875b60 73 #undef DBG
iva2k 0:e614f7875b60 74 #undef DBG_END
iva2k 0:e614f7875b60 75 #define DBG(...)
iva2k 0:e614f7875b60 76 #define DBG_END()
iva2k 1:3ee499525aa5 77 #undef DBGFIXLF
iva2k 1:3ee499525aa5 78 #define DBGFIXLF(...)
iva2k 1:3ee499525aa5 79 #endif // __DEBUG
iva2k 0:e614f7875b60 80
iva2k 0:e614f7875b60 81 #ifdef __LWIP_DEBUG
iva2k 0:e614f7875b60 82 #ifndef __SNPRINTF
iva2k 0:e614f7875b60 83 #define __SNPRINTF
iva2k 0:e614f7875b60 84 #include "mbed.h"
iva2k 0:e614f7875b60 85
iva2k 0:e614f7875b60 86 //int snprintf(char *str, int size, const char *format, ...);
iva2k 1:3ee499525aa5 87 #endif // __SNPRINTF
iva2k 1:3ee499525aa5 88 #endif // __LWIP_DEBUG
iva2k 0:e614f7875b60 89
iva2k 0:e614f7875b60 90 #ifdef __LWIP_DEBUG
iva2k 0:e614f7875b60 91 #undef __DEBUG
iva2k 0:e614f7875b60 92 #endif
iva2k 0:e614f7875b60 93
iva2k 1:3ee499525aa5 94 //#endif // DBG_H