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:
Thu Sep 27 09:31:40 2012 +0000
Revision:
8:cdee0f2b6ff0
Parent:
4:d854fa394f85
Fixed binding to the new Ethernet LWIP api

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NegativeBlack 0:00d5bc4b46e1 1 /**
NegativeBlack 0:00d5bc4b46e1 2 * Copyright (c) 2012, Roy van Dam <roy@vandam-innovations.com>
NegativeBlack 0:00d5bc4b46e1 3 * All rights reserved.
NegativeBlack 0:00d5bc4b46e1 4 *
NegativeBlack 0:00d5bc4b46e1 5 * Redistribution and use in source and binary forms, with or without
NegativeBlack 0:00d5bc4b46e1 6 * modification, are permitted provided that the following conditions are met:
NegativeBlack 0:00d5bc4b46e1 7 *
NegativeBlack 0:00d5bc4b46e1 8 * 1. Redistributions of source code must retain the above copyright notice, this
NegativeBlack 0:00d5bc4b46e1 9 * list of conditions and the following disclaimer.
NegativeBlack 0:00d5bc4b46e1 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
NegativeBlack 0:00d5bc4b46e1 11 * this list of conditions and the following disclaimer in the documentation
NegativeBlack 0:00d5bc4b46e1 12 * and/or other materials provided with the distribution.
NegativeBlack 0:00d5bc4b46e1 13 *
NegativeBlack 0:00d5bc4b46e1 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
NegativeBlack 0:00d5bc4b46e1 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
NegativeBlack 0:00d5bc4b46e1 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NegativeBlack 0:00d5bc4b46e1 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
NegativeBlack 0:00d5bc4b46e1 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
NegativeBlack 0:00d5bc4b46e1 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
NegativeBlack 0:00d5bc4b46e1 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
NegativeBlack 0:00d5bc4b46e1 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
NegativeBlack 0:00d5bc4b46e1 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
NegativeBlack 0:00d5bc4b46e1 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NegativeBlack 0:00d5bc4b46e1 24 */
NegativeBlack 0:00d5bc4b46e1 25
NegativeBlack 0:00d5bc4b46e1 26 #ifndef _NETWORK_SOCKET_HPP_
NegativeBlack 0:00d5bc4b46e1 27 #define _NETWORK_SOCKET_HPP_
NegativeBlack 0:00d5bc4b46e1 28
NegativeBlack 3:d30db8752485 29 #include <cstring>
NegativeBlack 3:d30db8752485 30
NegativeBlack 3:d30db8752485 31 #include "mbed.h"
NegativeBlack 1:6956f6f96fef 32 #include "ip/endpoint.hpp"
NegativeBlack 8:cdee0f2b6ff0 33 #include "lwip/sockets.h"
NegativeBlack 8:cdee0f2b6ff0 34 #include "lwip/netdb.h"
NegativeBlack 0:00d5bc4b46e1 35
NegativeBlack 0:00d5bc4b46e1 36 namespace network {
NegativeBlack 0:00d5bc4b46e1 37
NegativeBlack 0:00d5bc4b46e1 38 class Socket
NegativeBlack 0:00d5bc4b46e1 39 {
NegativeBlack 0:00d5bc4b46e1 40 public:
NegativeBlack 0:00d5bc4b46e1 41 enum Status {
NegativeBlack 0:00d5bc4b46e1 42 Closed = 0,
NegativeBlack 0:00d5bc4b46e1 43 Open = 1,
NegativeBlack 0:00d5bc4b46e1 44 Listening = 2,
NegativeBlack 0:00d5bc4b46e1 45 Accepting = 3,
NegativeBlack 0:00d5bc4b46e1 46 Connected = 4,
NegativeBlack 0:00d5bc4b46e1 47 Disconnected = 5,
NegativeBlack 0:00d5bc4b46e1 48 Receiving = 6,
NegativeBlack 0:00d5bc4b46e1 49 Sending = 7
NegativeBlack 0:00d5bc4b46e1 50 };
NegativeBlack 0:00d5bc4b46e1 51
NegativeBlack 0:00d5bc4b46e1 52 protected:
NegativeBlack 0:00d5bc4b46e1 53 ip::Endpoint _remote_endpoint;
NegativeBlack 0:00d5bc4b46e1 54 ip::Endpoint _local_endpoint;
NegativeBlack 0:00d5bc4b46e1 55
NegativeBlack 0:00d5bc4b46e1 56 Status _status;
NegativeBlack 0:00d5bc4b46e1 57 int _socket;
NegativeBlack 0:00d5bc4b46e1 58
NegativeBlack 0:00d5bc4b46e1 59 public:
NegativeBlack 0:00d5bc4b46e1 60 Socket();
NegativeBlack 0:00d5bc4b46e1 61 virtual ~Socket();
NegativeBlack 0:00d5bc4b46e1 62
NegativeBlack 3:d30db8752485 63 virtual int open();
NegativeBlack 4:d854fa394f85 64 int close();
NegativeBlack 4:d854fa394f85 65 int bind(int port);
NegativeBlack 0:00d5bc4b46e1 66
NegativeBlack 3:d30db8752485 67 ip::Endpoint &getRemoteEndpoint();
NegativeBlack 3:d30db8752485 68 ip::Endpoint &getLocalEndpoint();
NegativeBlack 0:00d5bc4b46e1 69
NegativeBlack 0:00d5bc4b46e1 70 int getHandle();
NegativeBlack 0:00d5bc4b46e1 71 enum Status getStatus();
NegativeBlack 0:00d5bc4b46e1 72 };
NegativeBlack 0:00d5bc4b46e1 73
NegativeBlack 0:00d5bc4b46e1 74 } // namespace network
NegativeBlack 0:00d5bc4b46e1 75
NegativeBlack 0:00d5bc4b46e1 76 #endif // _NETWORK_SOCKET_HPP_