A new object oriented network api that can be used to replace the one provided by the EthernetInterface library.

Dependents:   NetRelais TCP_Client_Example TCP_Server_Example UDP_Server_Example ... more

Object oriented network interface for the mbed platform

Currently implemented:

  • Address
  • Endpoint
  • UDP Socket
  • TCP Socket
  • Databuffer
  • Select API

It depends on the EthernetInterface for the lwip network stack.

Please do not hesitate to contact me with any remarks, improvements or questions.

The API is also available for unix at GitHub: LibNosa

Examples

Committer:
NegativeBlack
Date:
Sat Nov 15 21:35:31 2014 +0000
Revision:
9:7ac7c29fea3d
Parent:
4:d854fa394f85
Fixed type warnings in address::formString().

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NegativeBlack 4:d854fa394f85 1 /**
NegativeBlack 4:d854fa394f85 2 * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
NegativeBlack 4:d854fa394f85 3 * All rights reserved.
NegativeBlack 4:d854fa394f85 4 *
NegativeBlack 4:d854fa394f85 5 * Redistribution and use in source and binary forms, with or without
NegativeBlack 4:d854fa394f85 6 * modification, are permitted provided that the following conditions are met:
NegativeBlack 4:d854fa394f85 7 *
NegativeBlack 4:d854fa394f85 8 * 1. Redistributions of source code must retain the above copyright notice, this
NegativeBlack 4:d854fa394f85 9 * list of conditions and the following disclaimer.
NegativeBlack 4:d854fa394f85 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
NegativeBlack 4:d854fa394f85 11 * this list of conditions and the following disclaimer in the documentation
NegativeBlack 4:d854fa394f85 12 * and/or other materials provided with the distribution.
NegativeBlack 4:d854fa394f85 13 *
NegativeBlack 4:d854fa394f85 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
NegativeBlack 4:d854fa394f85 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
NegativeBlack 4:d854fa394f85 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NegativeBlack 4:d854fa394f85 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
NegativeBlack 4:d854fa394f85 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
NegativeBlack 4:d854fa394f85 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
NegativeBlack 4:d854fa394f85 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
NegativeBlack 4:d854fa394f85 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
NegativeBlack 4:d854fa394f85 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
NegativeBlack 4:d854fa394f85 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NegativeBlack 4:d854fa394f85 24 */
NegativeBlack 4:d854fa394f85 25
NegativeBlack 4:d854fa394f85 26 #ifndef _NETWORK_TCP_SERVER_HPP_
NegativeBlack 4:d854fa394f85 27 #define _NETWORK_TCP_SERVER_HPP_
NegativeBlack 4:d854fa394f85 28
NegativeBlack 4:d854fa394f85 29 #include <vector>
NegativeBlack 4:d854fa394f85 30
NegativeBlack 4:d854fa394f85 31 #include "socket.hpp"
NegativeBlack 4:d854fa394f85 32
NegativeBlack 4:d854fa394f85 33 namespace network {
NegativeBlack 4:d854fa394f85 34 namespace tcp {
NegativeBlack 4:d854fa394f85 35
NegativeBlack 4:d854fa394f85 36 class Server
NegativeBlack 4:d854fa394f85 37 {
NegativeBlack 4:d854fa394f85 38 public:
NegativeBlack 4:d854fa394f85 39 enum Status {
NegativeBlack 4:d854fa394f85 40 Stopped = 0,
NegativeBlack 4:d854fa394f85 41 Running = 1,
NegativeBlack 4:d854fa394f85 42 };
NegativeBlack 4:d854fa394f85 43
NegativeBlack 4:d854fa394f85 44 protected:
NegativeBlack 4:d854fa394f85 45 Status _status;
NegativeBlack 4:d854fa394f85 46
NegativeBlack 4:d854fa394f85 47 Socket _socket;
NegativeBlack 4:d854fa394f85 48 std::vector<Socket *> _clients;
NegativeBlack 4:d854fa394f85 49
NegativeBlack 4:d854fa394f85 50 public:
NegativeBlack 4:d854fa394f85 51 Server();
NegativeBlack 4:d854fa394f85 52 ~Server();
NegativeBlack 4:d854fa394f85 53
NegativeBlack 4:d854fa394f85 54 int start(int port, int max_pending);
NegativeBlack 4:d854fa394f85 55 int stop();
NegativeBlack 4:d854fa394f85 56
NegativeBlack 4:d854fa394f85 57 int run(int timeout = 0);
NegativeBlack 4:d854fa394f85 58
NegativeBlack 4:d854fa394f85 59 // Todo: design callback interface
NegativeBlack 4:d854fa394f85 60 };
NegativeBlack 4:d854fa394f85 61
NegativeBlack 4:d854fa394f85 62 } // namespace tcp
NegativeBlack 4:d854fa394f85 63 } // namespace network
NegativeBlack 4:d854fa394f85 64
NegativeBlack 4:d854fa394f85 65 #endif // _NETWORK_TCP_SERVER_HPP_