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 * @file
iva2k 0:e614f7875b60 3 * Common functions used throughout the stack.
iva2k 0:e614f7875b60 4 *
iva2k 0:e614f7875b60 5 */
iva2k 0:e614f7875b60 6
iva2k 0:e614f7875b60 7 /*
iva2k 0:e614f7875b60 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
iva2k 0:e614f7875b60 9 * All rights reserved.
iva2k 0:e614f7875b60 10 *
iva2k 0:e614f7875b60 11 * Redistribution and use in source and binary forms, with or without modification,
iva2k 0:e614f7875b60 12 * are permitted provided that the following conditions are met:
iva2k 0:e614f7875b60 13 *
iva2k 0:e614f7875b60 14 * 1. Redistributions of source code must retain the above copyright notice,
iva2k 0:e614f7875b60 15 * this list of conditions and the following disclaimer.
iva2k 0:e614f7875b60 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
iva2k 0:e614f7875b60 17 * this list of conditions and the following disclaimer in the documentation
iva2k 0:e614f7875b60 18 * and/or other materials provided with the distribution.
iva2k 0:e614f7875b60 19 * 3. The name of the author may not be used to endorse or promote products
iva2k 0:e614f7875b60 20 * derived from this software without specific prior written permission.
iva2k 0:e614f7875b60 21 *
iva2k 0:e614f7875b60 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
iva2k 0:e614f7875b60 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
iva2k 0:e614f7875b60 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
iva2k 0:e614f7875b60 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
iva2k 0:e614f7875b60 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
iva2k 0:e614f7875b60 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
iva2k 0:e614f7875b60 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
iva2k 0:e614f7875b60 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
iva2k 0:e614f7875b60 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
iva2k 0:e614f7875b60 31 * OF SUCH DAMAGE.
iva2k 0:e614f7875b60 32 *
iva2k 0:e614f7875b60 33 * This file is part of the lwIP TCP/IP stack.
iva2k 0:e614f7875b60 34 *
iva2k 0:e614f7875b60 35 * Author: Simon Goldschmidt
iva2k 0:e614f7875b60 36 *
iva2k 0:e614f7875b60 37 */
iva2k 0:e614f7875b60 38
iva2k 0:e614f7875b60 39 #include "lwip/opt.h"
iva2k 0:e614f7875b60 40 #include "lwip/def.h"
iva2k 0:e614f7875b60 41
iva2k 0:e614f7875b60 42 /**
iva2k 0:e614f7875b60 43 * These are reference implementations of the byte swapping functions.
iva2k 0:e614f7875b60 44 * Again with the aim of being simple, correct and fully portable.
iva2k 0:e614f7875b60 45 * Byte swapping is the second thing you would want to optimize. You will
iva2k 0:e614f7875b60 46 * need to port it to your architecture and in your cc.h:
iva2k 0:e614f7875b60 47 *
iva2k 0:e614f7875b60 48 * #define LWIP_PLATFORM_BYTESWAP 1
iva2k 0:e614f7875b60 49 * #define LWIP_PLATFORM_HTONS(x) <your_htons>
iva2k 0:e614f7875b60 50 * #define LWIP_PLATFORM_HTONL(x) <your_htonl>
iva2k 0:e614f7875b60 51 *
iva2k 0:e614f7875b60 52 * Note ntohs() and ntohl() are merely references to the htonx counterparts.
iva2k 0:e614f7875b60 53 */
iva2k 0:e614f7875b60 54
iva2k 0:e614f7875b60 55 #if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN)
iva2k 0:e614f7875b60 56
iva2k 0:e614f7875b60 57 /**
iva2k 0:e614f7875b60 58 * Convert an u16_t from host- to network byte order.
iva2k 0:e614f7875b60 59 *
iva2k 0:e614f7875b60 60 * @param n u16_t in host byte order
iva2k 0:e614f7875b60 61 * @return n in network byte order
iva2k 0:e614f7875b60 62 */
iva2k 0:e614f7875b60 63 u16_t
iva2k 0:e614f7875b60 64 htons(u16_t n)
iva2k 0:e614f7875b60 65 {
iva2k 0:e614f7875b60 66 return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
iva2k 0:e614f7875b60 67 }
iva2k 0:e614f7875b60 68
iva2k 0:e614f7875b60 69 /**
iva2k 0:e614f7875b60 70 * Convert an u16_t from network- to host byte order.
iva2k 0:e614f7875b60 71 *
iva2k 0:e614f7875b60 72 * @param n u16_t in network byte order
iva2k 0:e614f7875b60 73 * @return n in host byte order
iva2k 0:e614f7875b60 74 */
iva2k 0:e614f7875b60 75 u16_t
iva2k 0:e614f7875b60 76 ntohs(u16_t n)
iva2k 0:e614f7875b60 77 {
iva2k 0:e614f7875b60 78 return htons(n);
iva2k 0:e614f7875b60 79 }
iva2k 0:e614f7875b60 80
iva2k 0:e614f7875b60 81 /**
iva2k 0:e614f7875b60 82 * Convert an u32_t from host- to network byte order.
iva2k 0:e614f7875b60 83 *
iva2k 0:e614f7875b60 84 * @param n u32_t in host byte order
iva2k 0:e614f7875b60 85 * @return n in network byte order
iva2k 0:e614f7875b60 86 */
iva2k 0:e614f7875b60 87 u32_t
iva2k 0:e614f7875b60 88 htonl(u32_t n)
iva2k 0:e614f7875b60 89 {
iva2k 0:e614f7875b60 90 return ((n & 0xff) << 24) |
iva2k 0:e614f7875b60 91 ((n & 0xff00) << 8) |
iva2k 0:e614f7875b60 92 ((n & 0xff0000UL) >> 8) |
iva2k 0:e614f7875b60 93 ((n & 0xff000000UL) >> 24);
iva2k 0:e614f7875b60 94 }
iva2k 0:e614f7875b60 95
iva2k 0:e614f7875b60 96 /**
iva2k 0:e614f7875b60 97 * Convert an u32_t from network- to host byte order.
iva2k 0:e614f7875b60 98 *
iva2k 0:e614f7875b60 99 * @param n u32_t in network byte order
iva2k 0:e614f7875b60 100 * @return n in host byte order
iva2k 0:e614f7875b60 101 */
iva2k 0:e614f7875b60 102 u32_t
iva2k 0:e614f7875b60 103 ntohl(u32_t n)
iva2k 0:e614f7875b60 104 {
iva2k 0:e614f7875b60 105 return htonl(n);
iva2k 0:e614f7875b60 106 }
iva2k 0:e614f7875b60 107
iva2k 0:e614f7875b60 108 #endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */