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

Files at this revision

API Documentation at this revision

Comitter:
NegativeBlack
Date:
Wed Jul 18 15:31:16 2012 +0000
Parent:
5:4b6bc10437cb
Child:
7:9796742904fa
Commit message:
Added support for using Buffer objects with the UDP socket send and receive methods.

Changed in this revision

udp/socket.cpp Show annotated file Show diff for this revision Revisions of this file
udp/socket.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/udp/socket.cpp	Wed Jul 18 14:35:02 2012 +0000
+++ b/udp/socket.cpp	Wed Jul 18 15:31:16 2012 +0000
@@ -46,6 +46,19 @@
 }
 
 int
+Socket::send(Buffer &buffer, ip::Address &address, int port)
+{
+    ip::Endpoint endpoint(address, port);
+    return this->send(buffer.pointer(), buffer.length(), endpoint);
+}
+
+int
+Socket::send(Buffer &buffer, ip::Endpoint &endpoint)
+{
+    return this->send(buffer.pointer(), buffer.length(), endpoint);
+}
+
+int
 Socket::send(void *data, size_t size, ip::Address &address, int port)
 {
     ip::Endpoint endpoint(address, port);
@@ -84,6 +97,17 @@
 }
 
 int
+Socket::receive(Buffer &buffer)
+{
+    int result = this->receive(buffer.pointer(), buffer.size());
+    if (result >= 0) {
+        buffer.setLength(result);
+    }
+    
+    return result;
+}
+
+int
 Socket::receive(void *data, size_t max_size)
 {
     return this->receive(data, max_size, this->_remote_endpoint);
--- a/udp/socket.hpp	Wed Jul 18 14:35:02 2012 +0000
+++ b/udp/socket.hpp	Wed Jul 18 15:31:16 2012 +0000
@@ -26,6 +26,7 @@
 #ifndef _NETWORK_UDP_SOCKET_HPP_
 #define _NETWORK_UDP_SOCKET_HPP_
 
+#include "../buffer.hpp"
 #include "../socket.hpp"
 #include "../ip/address.hpp"
 
@@ -38,9 +39,12 @@
         public:        
             int open();
         
+            int send(Buffer &buffer, ip::Address &address, int port);
+            int send(Buffer &buffer, ip::Endpoint &endpoint);
             int send(void *data, size_t size, ip::Address &address, int port);
             int send(void *data, size_t size, ip::Endpoint &endpoint);
             
+            int receive(Buffer &buffer);
             int receive(void *data, size_t max_size);
             int receive(void *data, size_t max_size, ip::Endpoint &endpoint);
     };