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:
Sat Jun 12 06:01:50 2010 +0000
Revision:
0:e614f7875b60

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iva2k 0:e614f7875b60 1 /*
iva2k 0:e614f7875b60 2 * Redistribution and use in source and binary forms, with or without modification,
iva2k 0:e614f7875b60 3 * are permitted provided that the following conditions are met:
iva2k 0:e614f7875b60 4 *
iva2k 0:e614f7875b60 5 * 1. Redistributions of source code must retain the above copyright notice,
iva2k 0:e614f7875b60 6 * this list of conditions and the following disclaimer.
iva2k 0:e614f7875b60 7 * 2. Redistributions in binary form must reproduce the above copyright notice,
iva2k 0:e614f7875b60 8 * this list of conditions and the following disclaimer in the documentation
iva2k 0:e614f7875b60 9 * and/or other materials provided with the distribution.
iva2k 0:e614f7875b60 10 * 3. The name of the author may not be used to endorse or promote products
iva2k 0:e614f7875b60 11 * derived from this software without specific prior written permission.
iva2k 0:e614f7875b60 12 *
iva2k 0:e614f7875b60 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
iva2k 0:e614f7875b60 14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
iva2k 0:e614f7875b60 15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
iva2k 0:e614f7875b60 16 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
iva2k 0:e614f7875b60 17 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
iva2k 0:e614f7875b60 18 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
iva2k 0:e614f7875b60 19 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
iva2k 0:e614f7875b60 20 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
iva2k 0:e614f7875b60 21 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
iva2k 0:e614f7875b60 22 * OF SUCH DAMAGE.
iva2k 0:e614f7875b60 23 *
iva2k 0:e614f7875b60 24 * This file is part of the lwIP TCP/IP stack.
iva2k 0:e614f7875b60 25 *
iva2k 0:e614f7875b60 26 * Author: Simon Goldschmidt
iva2k 0:e614f7875b60 27 *
iva2k 0:e614f7875b60 28 */
iva2k 0:e614f7875b60 29 #ifndef __LWIP_NETDB_H__
iva2k 0:e614f7875b60 30 #define __LWIP_NETDB_H__
iva2k 0:e614f7875b60 31
iva2k 0:e614f7875b60 32 #include "lwip/opt.h"
iva2k 0:e614f7875b60 33
iva2k 0:e614f7875b60 34 #if LWIP_DNS && LWIP_SOCKET
iva2k 0:e614f7875b60 35
iva2k 0:e614f7875b60 36 #include <stddef.h> /* for size_t */
iva2k 0:e614f7875b60 37
iva2k 0:e614f7875b60 38 #include "lwip/inet.h"
iva2k 0:e614f7875b60 39 #include "lwip/sockets.h"
iva2k 0:e614f7875b60 40
iva2k 0:e614f7875b60 41 /* some rarely used options */
iva2k 0:e614f7875b60 42 #ifndef LWIP_DNS_API_DECLARE_H_ERRNO
iva2k 0:e614f7875b60 43 #define LWIP_DNS_API_DECLARE_H_ERRNO 1
iva2k 0:e614f7875b60 44 #endif
iva2k 0:e614f7875b60 45
iva2k 0:e614f7875b60 46 #ifndef LWIP_DNS_API_DEFINE_ERRORS
iva2k 0:e614f7875b60 47 #define LWIP_DNS_API_DEFINE_ERRORS 1
iva2k 0:e614f7875b60 48 #endif
iva2k 0:e614f7875b60 49
iva2k 0:e614f7875b60 50 #ifndef LWIP_DNS_API_DECLARE_STRUCTS
iva2k 0:e614f7875b60 51 #define LWIP_DNS_API_DECLARE_STRUCTS 1
iva2k 0:e614f7875b60 52 #endif
iva2k 0:e614f7875b60 53
iva2k 0:e614f7875b60 54 #if LWIP_DNS_API_DEFINE_ERRORS
iva2k 0:e614f7875b60 55 /** Errors used by the DNS API functions, h_errno can be one of them */
iva2k 0:e614f7875b60 56 #define EAI_NONAME 200
iva2k 0:e614f7875b60 57 #define EAI_SERVICE 201
iva2k 0:e614f7875b60 58 #define EAI_FAIL 202
iva2k 0:e614f7875b60 59 #define EAI_MEMORY 203
iva2k 0:e614f7875b60 60
iva2k 0:e614f7875b60 61 #define HOST_NOT_FOUND 210
iva2k 0:e614f7875b60 62 #define NO_DATA 211
iva2k 0:e614f7875b60 63 #define NO_RECOVERY 212
iva2k 0:e614f7875b60 64 #define TRY_AGAIN 213
iva2k 0:e614f7875b60 65 #endif /* LWIP_DNS_API_DEFINE_ERRORS */
iva2k 0:e614f7875b60 66
iva2k 0:e614f7875b60 67 #if LWIP_DNS_API_DECLARE_STRUCTS
iva2k 0:e614f7875b60 68 struct hostent {
iva2k 0:e614f7875b60 69 char *h_name; /* Official name of the host. */
iva2k 0:e614f7875b60 70 char **h_aliases; /* A pointer to an array of pointers to alternative host names,
iva2k 0:e614f7875b60 71 terminated by a null pointer. */
iva2k 0:e614f7875b60 72 int h_addrtype; /* Address type. */
iva2k 0:e614f7875b60 73 int h_length; /* The length, in bytes, of the address. */
iva2k 0:e614f7875b60 74 char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
iva2k 0:e614f7875b60 75 network byte order) for the host, terminated by a null pointer. */
iva2k 0:e614f7875b60 76 #define h_addr h_addr_list[0] /* for backward compatibility */
iva2k 0:e614f7875b60 77 };
iva2k 0:e614f7875b60 78
iva2k 0:e614f7875b60 79 struct addrinfo {
iva2k 0:e614f7875b60 80 int ai_flags; /* Input flags. */
iva2k 0:e614f7875b60 81 int ai_family; /* Address family of socket. */
iva2k 0:e614f7875b60 82 int ai_socktype; /* Socket type. */
iva2k 0:e614f7875b60 83 int ai_protocol; /* Protocol of socket. */
iva2k 0:e614f7875b60 84 socklen_t ai_addrlen; /* Length of socket address. */
iva2k 0:e614f7875b60 85 struct sockaddr *ai_addr; /* Socket address of socket. */
iva2k 0:e614f7875b60 86 char *ai_canonname; /* Canonical name of service location. */
iva2k 0:e614f7875b60 87 struct addrinfo *ai_next; /* Pointer to next in list. */
iva2k 0:e614f7875b60 88 };
iva2k 0:e614f7875b60 89 #endif /* LWIP_DNS_API_DECLARE_STRUCTS */
iva2k 0:e614f7875b60 90
iva2k 0:e614f7875b60 91 #if LWIP_DNS_API_DECLARE_H_ERRNO
iva2k 0:e614f7875b60 92 /* application accessable error code set by the DNS API functions */
iva2k 0:e614f7875b60 93 extern int h_errno;
iva2k 0:e614f7875b60 94 #endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/
iva2k 0:e614f7875b60 95
iva2k 0:e614f7875b60 96 struct hostent *lwip_gethostbyname(const char *name);
iva2k 0:e614f7875b60 97 int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
iva2k 0:e614f7875b60 98 size_t buflen, struct hostent **result, int *h_errnop);
iva2k 0:e614f7875b60 99 void lwip_freeaddrinfo(struct addrinfo *ai);
iva2k 0:e614f7875b60 100 int lwip_getaddrinfo(const char *nodename,
iva2k 0:e614f7875b60 101 const char *servname,
iva2k 0:e614f7875b60 102 const struct addrinfo *hints,
iva2k 0:e614f7875b60 103 struct addrinfo **res);
iva2k 0:e614f7875b60 104
iva2k 0:e614f7875b60 105 #if LWIP_COMPAT_SOCKETS
iva2k 0:e614f7875b60 106 #define gethostbyname(name) lwip_gethostbyname(name)
iva2k 0:e614f7875b60 107 #define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \
iva2k 0:e614f7875b60 108 lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop)
iva2k 0:e614f7875b60 109 #define freeaddrinfo(addrinfo) lwip_freeaddrinfo(addrinfo)
iva2k 0:e614f7875b60 110 #define getaddrinfo(nodname, servname, hints, res) \
iva2k 0:e614f7875b60 111 lwip_getaddrinfo(nodname, servname, hints, res)
iva2k 0:e614f7875b60 112 #endif /* LWIP_COMPAT_SOCKETS */
iva2k 0:e614f7875b60 113
iva2k 0:e614f7875b60 114 #endif /* LWIP_DNS && LWIP_SOCKET */
iva2k 0:e614f7875b60 115
iva2k 0:e614f7875b60 116 #endif /* __LWIP_NETDB_H__ */